From: Jamal Soueidan Date: 2007-04-04T21:43:14+09:00 Subject: Re: Everything is a object? Eleanor McHugh wrote: > On 4 Apr 2007, at 11:02, Jamal Soueidan wrote: >> I have been reading about these various boolean returns, how Ruby look >> at them, as you mentioned false and nil is the only objects which are >> considered false. >> >> But I thought you did not need to define/declare any variables before >> using it, but this has been misunderstood, you should somehow >> assign the >> variable to something before trying to use it, since Ruby "Still" >> don't >> know what object it is, right? > > The point is that you don't have to define a variable before you make > an assignment to it, much like in older variants of BASIC. Assignment > implicitly declares the variable to exist within the specified scope. > However until you make an assignment the interpreter is not aware of > the variable's existence (because logically it does not yet exist) > and so attempts to reference it will fail to produce a reference to > an object. An attempt will also be made to apply the token to the > current object as a method, and if this too fails then the > interpreter has no choice but to flag an error condition because > semantically your program is broken - it makes no sense. :D So until I assign something to it, the interpreter would know nothing about what object it is. In C# you can declare every variable what type it is like this: String mystring; I assume I could do that in Ruby also: @var = String.new But no need since Ruby would take care of this automatic when you assign something to variables. When I write attributes in my code: attr_assoccer :var I assume > then < the interpreter knows only that @var is a object (base class)? So before I can use @var. - I can either declare it, so the interpreter knows something about it (base class object) OR - I can assign something to it, so the interpreter knows what type it is @var = 'string' -- Posted via http://www.ruby-forum.com/.