This link has been bookmarked by 19 people . It was first bookmarked on 24 Sep 2007, by swan lin.
-
08 Sep 11
Alessandro MuraroUsing attr_accessor defined two new methods for us, name to get the value, and name= to set it.
-
Using
attr_accessordefined two new methods for us,nameto get the value, andname=to set it.
-
-
19 Feb 11
-
Once the
gobject is created, it remembers that the name is Pat. Hmm, what if we want to get at the name directly? -
Nope, can’t do it.
-
Instance variables are hidden away inside the object. They’re not terribly hidden, you see them whenever you inspect the object, and there are other ways of accessing them, but Ruby uses the good object-oriented approach of keeping data sort-of hidden away.
-
If we want to just list methods defined for Greeter we can tell it to not include ancestors by passing it the parameter
false, meaning we don’t want methods defined by ancestors -
to_s(meaning convert something to a string, a method that’s defined by default for every object) -
easy way of providing access to an object’s variables.
-
In Ruby, you can open a class up again and modify it. The changes will be present in any new objects you create and even available in existing objects of that class.
-
Using
attr_accessordefined two new methods for us,nameto get the value, andname=to set it.
-
-
19 Jan 11
-
02 Jul 10
-
Instance variables are hidden away inside the object. They’re not terribly hidden, you see them whenever you inspect the object, and there are other ways of accessing them, but Ruby uses the good object-oriented approach of keeping data sort-of hidden away.
-
-
10 Jan 08
-
24 Sep 07
-
Ruby uses the good object-oriented approach of keeping data sort-of hidden away.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.