Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Created March 12, 2012 00:58
Show Gist options
  • Save tarcieri/2018986 to your computer and use it in GitHub Desktop.
Save tarcieri/2018986 to your computer and use it in GitHub Desktop.
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
@digitalextremist
Copy link

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).

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