Module: Ensurance::ArrayEnsure::ClassMethods
- Defined in:
- lib/ensurance/array_ensure.rb
Instance Method Summary collapse
Instance Method Details
#ensure(thing) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ensurance/array_ensure.rb', line 12 def ensure(thing) case thing.class.name when 'NilClass' nil when 'Hash' thing.to_a when 'String' begin [JSON.parse(thing)].flatten rescue JSON::ParserError thing.split(',') end else Array(thing) end end |
#ensure!(thing) ⇒ Object
29 30 31 32 33 |
# File 'lib/ensurance/array_ensure.rb', line 29 def ensure!(thing) result = self.ensure(thing) raise ArgumentError, "Cannot Array.ensure(#{thing || 'nil'})" unless result result end |