Skip to content

Commit

Permalink
Implement Hash#inspect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Harris committed Jan 17, 2010
1 parent 35a60c7 commit 0d5426e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
4 changes: 4 additions & 0 deletions lib/hamster/hash.rb
Expand Up @@ -132,6 +132,10 @@ def dup
def_delegator :self, :dup, :nub
def_delegator :self, :dup, :remove_duplicates

def inspect
"{#{reduce([]) { |memo, key, value| memo << "#{key.inspect} => #{value.inspect}"}.join(", ")}}"
end

end

end
18 changes: 1 addition & 17 deletions spec/hamster/set/inspect_spec.rb
Expand Up @@ -2,26 +2,10 @@

require 'hamster/set'

describe Hamster::List do
describe Hamster::Set do

describe "#inspect" do

describe "doesn't run out of stack space on a really big" do

it "stream" do
@list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
end

it "list" do
@list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
end

after do
@list.inspect
end

end

[
[[], "{}"],
[["A"], "{\"A\"}"],
Expand Down

0 comments on commit 0d5426e

Please sign in to comment.