Skip to content
Abica edited this page Sep 13, 2010 · 1 revision

the present form of:


Packit::Backend.create :something do | record |
  record.add :this, :value => 0b1100
  record.add :that, :value => 0b0110
end

changes to the more verbose form of:


Packit::Backend.create :something do
  add :this do
    value 0b1100
  end

  add :that do
    value 0b0110
  end
end

Packit::Backend.create :something do
  add :this do
    value do | left, right |
      Checksum.compute *( left + right ).sum
    end
  end

  add :that do
    value 0b0110
  end
end

possibly full block approach (arity.zero?):


add do
  name :something
  value "blah a billion times"
  length 50
end

shorthand possibilities:


add  { name :something ; value "blah a billion times" ; length 50 }
# accepts a hash as first argument if no block is passed
add :name => :something, :value => "blah a billion times", :length => 50
add  { name, value, length = :something, "blah a billion times", length 50 }
Clone this wiki locally