[Feature Proposal] Have ActiveSupport::OrderedOptions accept a block

I think it would be cool to have ActiveSupport::OrderedOptions accept a block that can be used for instantiating and setting basic options.

def get_options
  my_options = ActiveSupport::OrderedOptions.new
  my_options.one = 1
  my_options
end

would more concisely become:

def get_options
  ActiveSupport::OrderedOptions.new do |ops|
    ops.one = 1
  end
end

Thoughts?

You can easily accomplish this with Kernel#tap like so:

def get_options
  ActiveSupport::OrderedOptions.new.tap do |ops|
    ops.one = 1
  end
end

Cool! I didn’t know that. We can close the thread now.