Last active
August 29, 2015 14:10
-
-
Save aanand/696f1ce398aee5a9473e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if you define to_a | |
irb(main):001:0> class Foo | |
irb(main):002:1> def to_a | |
irb(main):003:2> puts "hi" | |
irb(main):004:2> [] | |
irb(main):005:2> end | |
irb(main):006:1> end | |
=> nil | |
irb(main):007:0> [*Foo.new] | |
hi | |
=> [] | |
irb(main):008:0> Array(Foo.new) | |
hi | |
=> [] | |
# nil.to_a is [] | |
irb(main):009:0> nil.to_a | |
=> [] | |
# if you don't define to_a | |
irb(main):010:0> class Bar | |
irb(main):011:1> end | |
=> nil | |
irb(main):012:0> [*Bar.new] | |
=> [#<Bar:0x007fb7c99867e0>] | |
irb(main):013:0> Array(Bar.new) | |
=> [#<Bar:0x007fb7c9987988>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment