Skip to content

Commit

Permalink
Someone stop me, please. This is what happens when you IM-pair with @…
Browse files Browse the repository at this point in the history
…jaknowlden
  • Loading branch information
toothrot committed Jul 9, 2010
1 parent 8ffbe46 commit 769bcdb
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/johnny_hash.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module JohnnyHash
def self.walk_the_line!(value, raise_on_missing)
if value.respond_to?(:json!) then value.json!(raise_on_missing) else value end
end

module Hash
def json!(raise_on_missing = true)
@raise_on_missing = raise_on_missing
Expand All @@ -8,17 +12,12 @@ class << self
alias_method :non_json_reader, :[]

def [](key)
json_result!(non_json_reader(key))
JohnnyHash.walk_the_line!(non_json_reader(key), @raise_on_missing)
end

def method_missing(sym, *args, &block)
self[sym] || self[sym.to_s] || (super if @raise_on_missing)
end

private
def json_result!(result)
if result.respond_to?(:json!) then result.json!(@raise_on_missing) else result end
end
end
end

Expand All @@ -28,7 +27,7 @@ def json_result!(result)

module Array
def json!(raise_on_missing = true)
each {|element| if element.respond_to?(:json!) then element.json!(raise_on_missing) else element end }
each {|element| JohnnyHash.walk_the_line!(element, raise_on_missing) }
end
end
end
Expand Down

2 comments on commit 769bcdb

@gus
Copy link

@gus gus commented on 769bcdb Jul 10, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You remind me of a boy named Sue. You're gonna cry, cry, cry.

@toothrot
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lay off that whiskey, and let that Hash be!

Please sign in to comment.