Hi, here is the example of the wrong usage of the `super` keyword
trying to override the attribute method.
class User < ActiveRecord::Base
def name
super.to_s.capitalize
end
end
The result of this code looks 'pseudo'-correct and some people assume
it's fine to use that like if it were self[:name].to_s.capitalize
If we take a look at the code below - the results are different:
class User < ActiveRecord::Base
def name
'hi ' + super.to_s.capitalize
end
end
u = User.first
p u.name # => 'hi Hi bob'
p u.name # => 'hi Bob'
p u.name # => 'hi Bob'
My question is why the first call to u.name produces that result.
I'm looking at
if self.class.generated_methods.include?(method_name)
return self.send(method_id, *args, &block)
end
in
module ActiveRecord
module AttributeMethods
def method_missing
but need some help to figure the things out.
Simply want to know what is actually happening...
--
Thanks, Ivan Povalyukhin
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.