opal/opal — pull request #494 by chesterbr (2014-02-04 06:25:56+00:00)
Title: Adding Fixnum#[] (bits as element references)

As defined in http://www.ruby-doc.org/core-1.9.3/Fixnum.html#method-i-5B-5

Two things to consider:

1) MRI implementation seems to coerce Bignum into Fixnum, resulting in bits outside Fixnum range being always zero, hence the boundary check. Variables can be made into proper class constants if desired (didn't do it to avoid introducing anything outside the function scope)

2) Wasn't sure if Opal targets 32 or 64 bit, so I assumed the 64-bit range. Can change to 32-bit if desired, will likely pass the tests the same way, since mspec tests against a very large number (https://github.com/rubyspec/mspec/blob/61233407115b28eaa967fee41003caa6319ff630/lib/mspec/helpers/numeric.rb#L10-L12)

(P.S.: Awesome project! I'm trying to run https://github.com/chesterbr/ruby2600 on it - which relies heavily on bit fiddling, hence the PR. Cheers)