7stud2
(7stud --)
17 October 2013 19:18
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 ?
···
--
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.
7stud2
(7stud --)
17 October 2013 19:30
4
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/\ .
7stud2
(7stud --)
17 October 2013 19:49
5
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/\ .
7stud2
(7stud --)
17 October 2013 20:05
6
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/\ .
John_Moon
(John Moon)
18 October 2013 13:48
7
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