All_symbols array in irb

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

On Feb 22, 2014, at 16:56, gvim [email protected] 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]

On 23/02/2014 01:52, Ryan D. 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

On Feb 22, 2014, at 18:12, gvim [email protected] 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.

On Feb 22, 2014, at 7:56 PM, gvim [email protected] 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 S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.