Method: HtmlTemplate#to_recursive_ostruct

Defined in:
lib/html/template.rb

#to_recursive_ostruct(o) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/html/template.rb', line 217

def to_recursive_ostruct( o )
  if o.is_a?( Array )
    o.reduce( [] ) do |ary, item|
                     ary << to_recursive_ostruct( item )
                     ary
                   end
  elsif o.is_a?( Hash )
    ## puts 'to_recursive_ostruct (hash):'
    OpenStruct.new( o.reduce( {} ) do |hash, (key, val)|
                                     ## puts "#{key} => #{val}:#{val.class.name}"
                                     hash[key] = to_recursive_ostruct( val )
                                     hash
                                   end )
  else  ## assume regular "primitive" value - pass along as is
    o
  end
end