Forum: Ruby all_symbols array in irb

0946b736110f6af95c93bce0ea6d46ff?d=identicon&s=25 Gerald Vim (gvim)
on 2014-02-23 01:57
(Received via mailing list)
According to "The Well Grounded Rubyist" 2nd edition the following
should increment the size of the all_symbols array by 2 for variables a
and b but it doesn't:

>> Symbol.all_symbols.size
=> 3812
>> a = 1
=> 1
>> Symbol.all_symbols.size
=> 3812
>> b = 2
=> 2
>> Symbol.all_symbols.size
=> 3812
>> Symbol.all_symbols.include? :a
=> true
>> Symbol.all_symbols.include? :b
=> true
>> Symbol.all_symbols.size
=> 3812

I'm running Ruby version 2.1.0 on Mac OS X.

gvim
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2014-02-23 02:53
(Received via mailing list)
On Feb 22, 2014, at 16:56, gvim <gvimrc@gmail.com> wrote:

>>> Symbol.all_symbols.size
> => 3812
>>> Symbol.all_symbols.include? :a
> => true
>>> Symbol.all_symbols.include? :b
> => true
>>> Symbol.all_symbols.size
> => 3812
>
> I'm running Ruby version 2.1.0 on Mac OS X.

That's certainly true _in_theory_ but you're running irb, which is a
complicated mess:

>> Symbol.all_symbols.sort.grep(/^a/).first 5
=> [:a, :a1, :a2, :abort, :abort_on_exception]

but even without irb, there's plenty of symbols defined:

10004 % ruby -e 'p Symbol.all_symbols.sort.grep(/^a/).first 5'
[:a, :abort, :abort_on_exception, :abort_on_exception=, :abs]
0946b736110f6af95c93bce0ea6d46ff?d=identicon&s=25 Gerald Vim (gvim)
on 2014-02-23 03:12
(Received via mailing list)
On 23/02/2014 01:52, Ryan Davis wrote:

> That's certainly true _in_theory_ but you're running irb, which is a complicated
mess:
>
>>> Symbol.all_symbols.sort.grep(/^a/).first 5
> => [:a, :a1, :a2, :abort, :abort_on_exception]
>
> but even without irb, there's plenty of symbols defined:
>
> 10004 % ruby -e 'p Symbol.all_symbols.sort.grep(/^a/).first 5'
> [:a, :abort, :abort_on_exception, :abort_on_exception=, :abs]
>

So irb is different? Might explain why I also get this:

>> require 'date'
=> false
>> require 'time'
=> true

gvim
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2014-02-23 03:42
(Received via mailing list)
On Feb 22, 2014, at 18:12, gvim <gvimrc@gmail.com> wrote:

>> [:a, :abort, :abort_on_exception, :abort_on_exception=, :abs]
>>
>
> So irb is different? Might explain why I also get this:
>
>>> require 'date'
> => false
>>> require 'time'
> => true

I wouldn't call it different... but IRB loads code. A lot of it.
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2014-02-23 04:37
(Received via mailing list)
On Feb 22, 2014, at 7:56 PM, gvim <gvimrc@gmail.com> wrote:

>>> Symbol.all_symbols.size
> gvim
Did you check to see if :a and :b already existed?

~ ∙ pry
[1] pry(main)> Symbol.all_symbols.size
=> 14199
[2] pry(main)> Symbol.all_symbols.include? :a
=> true
[3] pry(main)> Symbol.all_symbols.size
=> 14199
[4] pry(main)> an_unlikely_name_to_see_if_we_get_a_new_symbol = 5
=> 5
[5] pry(main)> Symbol.all_symbols.size
=> 14200
[6] pry(main)> RUBY_VERSION
=> "2.1.0"

--

Mike Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.