Sha256: ae880ff92c72a2ada40d72c865fefb03b759961f984d4315b6e85212b6061631
Contents?: true
Size: 734 Bytes
Versions: 2
Compression:
Stored size: 734 Bytes
Contents
# encoding: utf-8 require 'attr_enumerable/attr_enumerable_helper' # AttrEnumerable module AttrEnumerable private def slice_attr(attribute, method_name, *args, &block) check_argument_length(*args) col = collection index_or_range = args.first length = args.size > 1 ? args[1] : nil fail ArgumentError, "invalid attribute #{attribute}" unless include_attr?(col.first, attribute) attrs = col.map { |e|e.send(attribute) } length ? attrs.slice(index_or_range, length) : attrs.slice(index_or_range) end def check_argument_length(*args) return if args.size > 0 fail ArgumentError, 'wrong number of arguments (0 for 1..2) (ArgumentError)' end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tbpgr_utils-0.0.151 | lib/attr_enumerable/slice_attr.rb |
tbpgr_utils-0.0.150 | lib/attr_enumerable/slice_attr.rb |