Skip to content

Commit

Permalink
add Hashie::Mash#extractable_options?
Browse files Browse the repository at this point in the history
  • Loading branch information
ridiculous committed Jan 19, 2015
1 parent 32d904b commit 86a1415
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Expand Up @@ -12,7 +12,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 165
Max: 170

# Offense count: 8
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
* [#254](https://github.com/intridea/hashie/pull/254): Added public utility methods for stringify and symbolize keys - [@maxlinc](https://github.com/maxlinc).
* [#261](https://github.com/intridea/hashie/pull/261): Fixed bug where Dash.property modifies argument object - [@d_tw](https://github.com/d_tw).
* [#264](https://github.com/intridea/hashie/pull/264): Methods such as abc? return true/false with Hashie::Extensions::MethodReader - [@Zloy](https://github.com/Zloy).
* [#269](https://github.com/intridea/hashie/pull/269): Add #extractable_options? so ActiveSupport Array#extract_options! can extract it - [@ridiculous](https://github.com/ridiculous).
* Your contribution here.

## 3.3.2 (11/26/2014)
Expand Down
5 changes: 5 additions & 0 deletions lib/hashie/mash.rb
Expand Up @@ -250,6 +250,11 @@ def method_missing(method_name, *args, &blk)
end
end

# play nice with ActiveSupport Array#extract_options!
def extractable_options?
true
end

protected

def method_suffix(method_name)
Expand Down
12 changes: 12 additions & 0 deletions spec/hashie/mash_spec.rb
Expand Up @@ -639,4 +639,16 @@ class SubMash < Hashie::Mash
end
end
end

describe '#extractable_options?' do
require 'active_support'

subject { described_class.new(name: 'foo') }
let(:args) { [101, 'bar', subject] }

it 'can be extracted from an array' do
expect(args.extract_options!).to eq subject
expect(args).to eq [101, 'bar']
end
end
end

0 comments on commit 86a1415

Please sign in to comment.