alcina
October 17, 2013, 9:18pm
#1
Can anyone tell me what’s happening in the below code ?
c = 0b101010011
c # => 339
c[0] # => 1
c[1] # => 1
c[2] # => 0
c[3] # => 0
c[4] # => 1
here c
is not an array,but how then c[0],c[1], etc producing output
and how those outputs are coming ?
my-ruby
October 17, 2013, 9:21pm
#2
See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for
example.
Nothing special, just another method lookup.
my-ruby
October 17, 2013, 9:30pm
#3
Adam P. wrote in post #1124779:
See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for
example.
Nothing special, just another method lookup.
Ohh! somehow I overlooked that method in the documentation.
Thanks
my-ruby
October 17, 2013, 9:32pm
#4
On Oct 17, 2013, at 2:21 PM, Adam P. [email protected] wrote:
See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for example.
Nothing special, just another method lookup.
You truly do have superpowers.
my-ruby
October 17, 2013, 9:49pm
#5
Adam P. wrote in post #1124779:
See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for
example.
Nothing special, just another method lookup.
can you explain the below code ?
12 === Fixnum # => false
Fixnum === 12 # => true
Why different result is getting printed?
my-ruby
October 18, 2013, 3:50pm
#6
I think it’s a matter of order it comes in.
It is similar to saying
"string’ === String # => false
String === “string” # => true.
my-ruby
October 18, 2013, 5:21pm
#7
On Fri, Oct 18, 2013 at 3:48 PM, John M. [email protected] wrote:
I think it’s a matter of order it comes in.
It is similar to saying
"string’ === String # => false
String === “string” # => true.
http://en.wikipedia.org/wiki/Commutative
Cheers
robert
my-ruby
October 17, 2013, 10:05pm
#8
Love U Ruby wrote in post #1124783:
Adam P. wrote in post #1124779:
See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for
example.
Nothing special, just another method lookup.
can you explain the below code ?
12 === Fixnum # => false
Fixnum === 12 # => true
Why different result is getting printed?
After spending some time I figured it out:
Why Fixnum === 12 # => true
?
Fixnum.respond_to?(:===) # => true
Fixnum.method(:===).owner # => Module
As per the documentation of Module#===
Case Equality—Returns true if anObject is an instance of mod or one
of mod’s descendants. Of limited use for modules, but can be used in
case statements to classify objects by class.
Why 12 === Fixnum # => false
?
Got answer from here -
http://www.ruby-doc.org/core-2.0.0/Fixnum.html#method-i-3D-3D-3D