Method: ListTool::List#initialize
- Defined in:
- lib/list_tool/list.rb
#initialize(arg = nil) ⇒ List
Returns a new instance of List.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/list_tool/list.rb', line 8 def initialize(arg=nil) if arg.respond_to?(:to_str) @name = arg @items = [] elsif arg.is_a?(Hash) prepare_data(arg) @name = arg['name'] @items = [] arg['items'].each do |item| add_item(item) end else raise(ArgumentError, "argument expected to be Hash or String, #{arg.class} given") end end |