The device model has the following attributes: name, version, and full_name
Full name is name + version:
class Device < ActiveRecord::Base def prepare full_name = (!show_version || version.nil?)? name : name + " " + version.to_s end end
When I do the following:
d = Device.new :name => "iPhone", :version => "4" d.prepare d.full_name
I get nil for the attribute "full_name"
When I use "self", it works:
class Device < ActiveRecord::Base def prepare self.full_name = (!show_version || version.nil?)? name : name + " " + version.to_s end end
Performing "prepare", I get "iPhone 4" for the attribute "full_name".
Some people have told me that this is a good way to avoid using the "I" inside class methods. But it brings problems.
Question: why doesnβt it work without using "I"?
source share