Rails

Could someone explain to me:

class Movie << ActiveRecord::Base
has_many :Actors
end

How can I call a method within class definition ? This is not Ruby
anymore.
And this : semicolon stands for symbol. Never heard of symbols in Ruby.

On Mon, Jul 27, 2009 at 4:25 PM, Haris Bogdanović[email protected]
wrote:

Could someone explain to me:

class Movie << ActiveRecord::Base
  has_many :Actors
end

How can I call a method within class definition ? This is not Ruby anymore.

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
=> nil
irb(main):006:0> class Movie < Base
irb(main):007:1> has_many :Actors
irb(main):008:1> end
I have many Actors
=> nil

And this : semicolon stands for symbol. Never heard of symbols in Ruby.

http://onestepback.org/index.cgi/Tech/Ruby/SymbolsAreNotImmutableStrings.red

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs