That's correct. The Kernel module is mixed into Object (and hence is
available in every object as every object is a descendant of Object).
Farrel
···
2008/7/24 matu <m@t.u>:
oh. i found out: it comes from Kernel. put this raises another question: are
all methods of Kernel available in Object? is Kernel always mixed in or
something like that?
--
Aimred - Ruby Development and Consulting
Farrel Lifson wrote:
That's correct. The Kernel module is mixed into Object (and hence is
available in every object as every object is a descendant of Object).
Ok. Thank you both. But...
hi.rb:
module Hi
def ola
p 'ola'
end
end
require 'hi'
=> true
include Hi
=> Object
Object.methods.include? 'ola'
=> true
ola
"ola"
=> nil
Object.methods.include? 'p'
=> false
WTF? Why does Object.methods not include p? Kernel is mixed in like my Hi
module, right? So why does Object.methods include ola, but not p?
It does. You just need to know that it's a private method:
>> Object.private_methods.include? "p"
=> true
James Edward Gray II
···
On Jul 24, 2008, at 2:39 PM, matu wrote:
To make sure you can't do this:
some_rand_obj.p …
It's private, so Ruby knows that is no good.
James Edward Gray II
···
On Jul 24, 2008, at 2:54 PM, matu wrote:
James Gray wrote:
It does. You just need to know that it's a private method:
Object.private_methods.include? "p"
=> true
Doh! 
May I ask why?
They are both String objects and there is no difference between them.
What is different is how you can define them. You can use "…" or '…' to construct String objects with different rules about how the content will be treated.
James Edward Gray II
···
On Jul 24, 2008, at 3:09 PM, matu wrote:
matu wrote:
Doh! 
May I ask why?
All right... I am starting to look like a 3y old why, why, why, why...
But today I have some time, and I am playing around, and there is something
else that surprises me a bit:
"".class
=> String
''.class
=> String
They are both String classes, but as we all know, they behave differently.
How?
matu wrote:
James Gray wrote:
What is different is how you can define them. You can use "…" or '…'
to construct String objects with different rules about how the content
will be treated.
clear as mud
thanks!
like so...
irb(main):001:0> h='huh?'
=> "huh?"
irb(main):002:0> p '#{h}'
"\#{h}"
=> nil
irb(main):003:0> p "#{h}"
"huh?"
=> nil
···
--
Posted via http://www.ruby-forum.com/\.