Sha256: e64107ee6388e3caf1883cfaa255fb2186773af0440f204c2b78b180dd884d43

Contents?: true

Size: 592 Bytes

Versions: 6

Compression:

Stored size: 592 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

# Extensions for Struct

class Struct

  # Action = Struct.new('Action', :template, :method, :params)
  #
  # a = Action.fill(:template => nil, :method => :meth, :params => [1])
  # # => #<struct Struct::Action template=nil, method=:meth, params=[1]>

  def self.fill(hash = {})
    instance = new
    hash.each do |key, value|
      next unless members.include?(key.to_s)
      instance.send("#{key}=", value)
    end
    instance
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ramaze-0.1.4 lib/ramaze/snippets/struct/fill.rb
ramaze-0.1.1 lib/ramaze/snippets/struct/fill.rb
ramaze-0.1.2 lib/ramaze/snippets/struct/fill.rb
ramaze-0.1.3 lib/ramaze/snippets/struct/fill.rb
ramaze-0.2.1 lib/ramaze/snippets/struct/fill.rb
ramaze-0.2.0 lib/ramaze/snippets/struct/fill.rb