Created
March 12, 2012 00:58
-
-
Save tarcieri/2018986 to your computer and use it in GitHub Desktop.
This file contains 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
require 'celluloid' | |
class ConcurrentNestedHash | |
include Celluloid | |
def initialize | |
@outer = {} | |
end | |
def [](*keys) | |
keys.inject(@outer) { |h,k| h[k] } | |
end | |
def []=(*args) | |
value = args.pop | |
raise ArgumentError, "wrong number of arguments (1 for 2)" if args.empty? | |
key = args.pop | |
hash = args.inject(@outer) { |h,k| h[k] ||= {} } | |
hash[key] = value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wait I got it.
def sort_by( &block ); @outer.sort_by &block end
Missed the second ampersand inside the method, not just in the definition (when passing a block and not *args).