Variable assignment like functions in ruby
If you don't like the orthodox way of assigning value to the instance variables of a class like Object.setProperty(value), you can use ruby's syntactic sugar to just write something that looks like Object.property = value All you need to do is to have an instance method with name property=
For example, have a class like
Class Person
def name=(name)
@name = name
end
end
Now you can create a new instance and assign name as following
nik = Person.new
nik.name=('nik')
or
nik.name='nik'
or even
nik.name = 'nik'
Written by Nikhil Lingutla
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#