Could someone explain to me:
class Movie << ActiveRecord::Base
=C2=A0 =C2=A0has_many :Actors
end
How can I call a method within class definition ? This is not Ruby anymor=
e.
In fact it is. A method call without an explicit receiver goes to
whatever object happens to be "self". Inside a class definition, self
is the class object, in this case Movie (which is an instance of class
Class). Remember than in Ruby classes are objects too. Check this, for
example:
irb(main):001:0> class Base
irb(main):002:1> def self.has_many(thing)
irb(main):003:2> puts "I have many #{thing}"
irb(main):004:2> end
irb(main):005:1> end
=3D> nil
irb(main):006:0> class Movie < Base
irb(main):007:1> has_many :Actors
irb(main):008:1> end
I have many Actors
=3D> nil
And this : semicolon stands for symbol. Never heard of symbols in Ruby.
http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.re=
d
Check here for example for some explanations of symbols, although with
1.9 I believe they have become more string-like than in 1.8
Hope this helps,
Jesus.