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 |
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
@tarcieri, how can sort_by be carried over here? I know a block must be passed, often with 1 or 2 parameters on the block. I've tried several ways of passing a block, and parameters into the block, for this gist:
https://gist.github.com/digitalextremist/5406223
Latest attempt:
def sort_by( *args ); @outer.sort_by yield( args ) end