Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
What is the difference between :foo and "foo" ?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Steve Litt, post: 4498854"] OK, let me see if I'm correctly understanding you. :wilbur is an object. That object has two properties, which one could call, in generic and not Ruby terms, a key and a value. The key is an integer. The value is "wilbur". Neither the key nor the value can be changed during the execution of the program. When we write: attr_accessor :wilbur what really happens is that the function attr_accessor() takes symbol :wilbur as an argument, tacks on a @ to the string's value in order to make the true class variable [USER=53238]@wilbur[/USER], and then writes a tiny get and set functions whose names are wilbur, such that: my_object.wilbur = 22 puts my_object.wilbur So my initial comment that it seemed like magic is true only to the extent that the "magic" performed by attr_accessor is to create the set and get methods with the same name as the symbol that is its argument. Do I understand what you're saying? Thanks SteveT Steve Litt [URL]http://www.troubleshooters.com[/URL] [email]slitt@troubleshooters.com[/email] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
What is the difference between :foo and "foo" ?
Top