module Cnblog2jekyll
class << self
attr_accessor :username
[:archive_links, :article_links].each do |method_name|
define_method method_name do
instance_value = instance_variable_get(("@" + method_name.to_s).to_sym)
instance_value ? instance_value : send("get_" + method_name.to_s)
# @archive_links ? @archive_links : get_archive_links
end
end
binding.pry
def test
binding.pry
end
end
end
Please ignore meaning of most part code and mind the place of 'binding.pry'.
Here comes the question: I type in 'self' in the pry console just at the place of 'binding.pry', and it give this result:
From: /home/yanying/cnblog2jekyll/lib/cnblog2jekyll.rb @ line 20 :
15: instance_value = instance_variable_get(("@" + method_name.to_s).to_sym)
16: instance_value ? instance_value : send("get_" + method_name.to_s)
17: # @archive_links ? @archive_links : get_archive_links
18: end
19: end
=> 20: binding.pry
21:
22: def test
23: binding.pry
24: end
25:
[1] pry(#<Class>)> self
=> #<Class:Cnblog2jekyll>
[2] pry(#<Class>)> self.class
=> Class
[3] pry(#<Class>)> self.ancestors
=> [#<Class:Cnblog2jekyll>, Module, Object, PP::ObjectMixin, Kernel, BasicObject]
[4] pry(#<Class>)>
=> true
[2] pry(main)> Cnblog2jekyll.test
From: /home/yanying/cnblog2jekyll/lib/cnblog2jekyll.rb @ line 23 Cnblog2jekyll.test:
22: def test
=> 23: binding.pry
24: end
[1] pry(Cnblog2jekyll)> self
=> Cnblog2jekyll
[2] pry(Cnblog2jekyll)> self.class
=> Module
[3] pry(Cnblog2jekyll)> self.ancestors
=> [Cnblog2jekyll]
[4] pry(Cnblog2jekyll)>
So, my question is: Why the first result of 'self' is a 'Class'? But the second of it is a "Module"? What's the magic here?