P
Patrick Doyle
Sorry if this is a FAQ, but I was just looking at some Ruby code and
came across the following construct:
class << self
def blahblahblah
...
end
end
I wondered what that did, went looking, and came across this email
thread from 2002:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/57244, in
reading that, I came across this (slightly modified) code:
class A
B = 12
def self.a
puts "class method A::a : #{B}"
end
def A.b
puts "class method A::b : #{B}"
end
class << self
B = 24
def c
puts "class method A::c : #{B}"
end
end
end
A.a
A.b
A.c
puts "A::B : #{A::B}"
Could somebody enlighten me as to what is going on here? I didn't
completely follow all of the ins & outs of the thread, nor why
def self.a
is better/different than
def A.a
is better different than
class << self
def a
Can anybody comment or point me in the direction of some enlightenment?
--wpd
came across the following construct:
class << self
def blahblahblah
...
end
end
I wondered what that did, went looking, and came across this email
thread from 2002:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/57244, in
reading that, I came across this (slightly modified) code:
class A
B = 12
def self.a
puts "class method A::a : #{B}"
end
def A.b
puts "class method A::b : #{B}"
end
class << self
B = 24
def c
puts "class method A::c : #{B}"
end
end
end
A.a
A.b
A.c
puts "A::B : #{A::B}"
Could somebody enlighten me as to what is going on here? I didn't
completely follow all of the ins & outs of the thread, nor why
def self.a
is better/different than
def A.a
is better different than
class << self
def a
Can anybody comment or point me in the direction of some enlightenment?
--wpd