Skip to content

Instantly share code, notes, and snippets.

@aanand
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aanand/696f1ce398aee5a9473e to your computer and use it in GitHub Desktop.
Save aanand/696f1ce398aee5a9473e to your computer and use it in GitHub Desktop.
# 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