Skip to content

Instantly share code, notes, and snippets.

@justinko
Created May 21, 2011 20:44
Show Gist options
  • Save justinko/984878 to your computer and use it in GitHub Desktop.
Save justinko/984878 to your computer and use it in GitHub Desktop.
class H < Array
def a
reject {|i| i == :a}
end
def b
select {|i| i == :b}
end
def c
select {|i| i == :c}
end
end
foo = H.new
foo << :a
foo << :b
foo << :c
puts foo.a.b.c # => NoMethodError: undefined method ‘c’ for [:b]:Array
class H < Array
def a
reject {|i| i == :a}
end
def b
new { select {|i| i == :b} }
end
def c
select {|i| i == :c}
end
def new
self.class.new yield
end
end
foo = H.new
foo << :a
foo << :b
foo << :c
puts foo.a.b.c.inspect # => []
class H < Array
def a
reject {}
end
def b
select {}
end
end
foo = H.new
puts foo.a.class.inspect # => H
puts foo.b.class.inspect # => Array
@justinko
Copy link
Author

Behavior is on 1.8.7 and 1.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment