Issue #14583 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Feedback

It doesn't help that you are not providing neither a minimal code example, nor even a stacktrace.

The line giving you an error has many expressions, so it's impossible to know if the error actually occurs in `resource.method(:valid_attribute?)` or within `write_attributes_via_call`.

Also, it's not clear if you are copy pasting the error messages directly or not, as the first error is for class `PhotoRealizer` while the last is  for class `#<Class:#<PhotoRealizer:0x00007fa16d608c98>>', which is looks like a singleton class of a class.

Note that there are ways to get a case where calling a method `foo` works, but not `method(:foo)`: define `method_missing?` but not `respond_to_missing?`. I don't think that's the issue here; it looks like if somehow, somewhere, the code executed is `PhotoRealizer.method(:valid_attribute?)` which fails. Indeed, the "hint" given, `alias_attribute`, is a method defined on Classes & Modules.

Please dig a bit deeper into this, and if you actually find a bug with `method` provide a minimal code example to reproduce it.

HTH, good luck.

----------------------------------------
Bug #14583: #method() is reporting the wrong self in exception
https://bugs.ruby-lang.org/issues/14583#change-70850

* Author: krainboltgreene (Kurtis Rainbolt-Greene)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
This is hard to explain but I'll do my best:

When running an rspec test I get this exception:

~~~
  Failure/Error: resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))

     NameError:
       undefined method `valid_attribute?' for class `PhotoRealizer'
       Did you mean?  alias_attribute
~~~

This is unequivocally wrong, so I go to prove it:

~~~
    13: def call
    14:   resource.model.tap do |model|
    15:     resource_class.write_attributes_via_call(model, {id: id}) if id
 => 16:     binding.pry
    17:     resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))
    18:     resource_class.write_attributes_via_call(model, relationships.select(&resource.method(:valid_relationship?)).transform_values(&resource.method(:as_relationship)))
    19:     resource_class.save_via_call(model)
    20:   end
    21: end

[1] pry(#<JSONAPI::Realizer::Action::Create>)> resource
=> #<PhotoRealizer:0x00007fa16d608c98 @model=#<Photo:0x00007fa16d608d38 @id="550e8400-e29b-41d4-a716-446655440000">>
[2] pry(#<JSONAPI::Realizer::Action::Create>)> resource.class
=> PhotoRealizer
[3] pry(#<JSONAPI::Realizer::Action::Create>)> resource.class.valid_attribute?
ArgumentError: wrong number of arguments (given 0, expected 2)
~~~

Turns out however, that I'm being silly and calling `method()` on an instance, so I exit out of my pry:

```
 Failure/Error: resource_class.write_attributes_via_call(model, attributes.select(&resource.method(:valid_attribute?)))

     NameError:
       undefined method `valid_attribute?' for class `#<Class:#<PhotoRealizer:0x00007fa16d608c98>>'
       Did you mean?  alias_attribute
```

Wait, what? How could this be? A different error now that I've observed?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>