Here is my sample code:
class Foo
Bar = 10
end
Foo::Bar # => 10
Foo::Bar.class # => Fixnum
10.class # => Fixnum
Float::NAN # => NaN
Float::NAN.class # => Float
NaN.class
Here is my sample code:
class Foo
Bar = 10
end
Foo::Bar # => 10
Foo::Bar.class # => Fixnum
10.class # => Fixnum
Float::NAN # => NaN
Float::NAN.class # => Float
NaN.class
class Foo
Bar = 10
end # => 10
Foo::Bar # => 10
Foo::Bar.class #=> Fixnum
Bar.class
NameError: uninitialized constant Object::Bar
from (irb):6
from /usr/local/ruby-1.9.2/bin/irb:12:in `’
NAN is namespaced under Float. So you can only access it through
Float::NAN.
–
Dheeraj K.
Dheeraj K. wrote in post #1119707:
NAN is namespaced under Float. So you can only access it through
Float::NAN.–
Dheeraj K.
Float::NAN # => NaN .
Does it mean constant NaN
holds the value also NaN
? As
Float::NAN.class
gives us the class name back Float
… I am confused
in this point…
Float::NAN.instace_of?(Float)
While Float::NAN.class # => Float
, How does the above error come out?
Float::NAN.is_a?(Object) # => true
It seems NaN
an instance but for class instance it is?
Dheeraj K. wrote in post #1119714:
Float::NAN is a constant which holds a special float value
NaN
@Dheeraj You are right…But my confusion is why then instance_of?
and
#class
are going against of each other?
Can you post the code you’re confused with?
–
Dheeraj K.
Float::NAN is a constant which holds a special float value NaN
–
Dheeraj K.
Dheeraj K. wrote in post #1119723:
Can you post the code you’re confused with?
See here :-
C:>irb --simple-prompt
Float::NAN
=> NaNFloat::NAN.class
=> FloatFloat::NAN.instace_of?(Float)
NoMethodError: undefined methodinstace_of?' for NaN:Float from (irb):3 from C:/Ruby193/bin/irb:12:in
’
On 27 August 2013 15:34, Love U Ruby [email protected] wrote:
Does it mean constant
NaN
holds the value alsoNaN
? As
Float::NAN.class
gives us the class name backFloat
… I am confused
in this point…
I /think/ that what is happening there is that the displayed text
=> NaN
is the result of ruby attempting to print the value of Float::NAN.
There is no constant NaN, it is just text displayed when it tries to
print the value of the Float constant Float::NAN. In other words
Float::NAN is a constant which is not actually any number at all and
when printed displays as NaN to show that it is not a number.
Colin
Dheeraj K. wrote in post #1119727:
You spelt it wrong.
instance_of?, not instace_of?
OMG!! Thanks for the pointer.
What value Float::NAN
contains ? If there is no value assigned to the
constant,then on what instance that #class
is called?
Float::NAN contains a special float value NaN.
–
Dheeraj K.
You spelt it wrong.
instance_of?, not instace_of?
–
Dheeraj K.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs