Confusion with Ruby binary number

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 ?

···

--
Posted via http://www.ruby-forum.com/.

You truly do have superpowers.

···

On Oct 17, 2013, at 2:21 PM, Adam Prescott <adam@aprescott.com> wrote:

See Class: Fixnum (Ruby 1.9.3) for example. Nothing special, just another method lookup.

See http://ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5D for example.
Nothing special, just another method lookup.

Adam Prescott wrote in post #1124779:

See Class: Fixnum (Ruby 1.9.3) for
example.
Nothing special, just another method lookup.

Ohh! somehow I overlooked that method in the documentation.

Thanks

···

--
Posted via http://www.ruby-forum.com/\.

Adam Prescott wrote in post #1124779:

See Class: Fixnum (Ruby 1.9.3) 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?

···

--
Posted via http://www.ruby-forum.com/\.

Love U Ruby wrote in post #1124783:

Adam Prescott wrote in post #1124779:

See Class: Fixnum (Ruby 1.9.3) 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 -

···

--
Posted via http://www.ruby-forum.com/\.

I think it's a matter of order it comes in.

It is similar to saying

"string' === String # => false
String === "string" # => true.

···

On Thu, Oct 17, 2013 at 3:49 PM, Love U Ruby <lists@ruby-forum.com> wrote:

Adam Prescott wrote in post #1124779:
> See Class: Fixnum (Ruby 1.9.3) 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?

--
Posted via http://www.ruby-forum.com/\.

--
John Moon

Cheers

robert

···

On Fri, Oct 18, 2013 at 3:48 PM, John Moon <johnmoonyy@gmail.com> wrote:

I think it's a matter of order it comes in.

It is similar to saying

"string' === String # => false
String === "string" # => true.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/