Reputation: 60067
How does Integer(543543534)
work given that Integer
is a
class? It doesn't seem to work with every class:
Numeric '4532432'
#=> NoMethodError: undefined method `Numeric' for main:Object
Is there a general way to construct an instance of a class SomeClass
from SomeClass
and a string 'somestring'
besides trying SomeClass.new('somestring')
or defining #to_X
?
Upvotes: 0
Views: 40
Reputation: 15791
When you call Integer(543543534)
, you invoke Kernel#Integer
method, which converts argument to Fixnum
or Bignum
. And Kernel
module is being included by Object
, so this is just a method call on Object
, it isn't related to Integer
class.
Upvotes: 2
Reputation: 168179
Integer
is not a class there.Kernel
).Upvotes: 2