Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash with a default_proc being set #347

Open
pnomolos opened this issue Oct 30, 2015 · 0 comments
Open

Hash with a default_proc being set #347

pnomolos opened this issue Oct 30, 2015 · 0 comments

Comments

@pnomolos
Copy link

pnomolos commented Oct 30, 2015

I'm trying to get a default_proc set for attributes, and I feel like either I'm missing something obvious or something wacky is going on. I've tried all of the following with no success:

attribute :features, Hash, default: Hash.new{ |h, k| h[k] = 0 }
attribute :features, Hash, default: ->(*){ Hash.new{ |h, k| h[k] = 0 } }
attribute :features, Hash, default: :create_default_proc

def create_default_proc
  Hash.new{ |h, k| h[k] = 0 }
end
attribute :features, Hash.new{ |h, k| h[k] = 0 }

In every case, I end up with something like:

obj = Foobar.new
obj.features # => {}

# The following should be 0
obj.features["blah"] # => nil 

# The following should not be nil
obj.features.default_proc # => nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant