2007年1月26日星期五

Singleton Class of Ruby

class T1
class <<>

def foo

puts "singleton method foo"

end

end

def self.foo

puts "class method foo"

end

end



The two method definition means the same thing, just like:

obj = T1.new

def obj.test
....
end

class <<>
....
end


T1's singleton class (in class <<>

module Kernel
def
singleton_class

class <<>
end
end

class Base
def self.new_method name
singleton_class.class_eval do
define_method(name) do m
puts m
end
end
#class_eval <<-EOF
# def self.#{name} m
# puts m
# end
#EOF
end
end

class NewClass <>
new_method :msg
end

NewClass.msg "aaa" #=>
aaa


2007年1月23日星期二

Where are you?

Purpose of Jim... Personal container to hold dribs and drabs of my poor technical idea. Not for show, just for save&load... so poor English is forgivable :)