I am trying to reduce the amount of code in on of my Ruby Classes by Iterating through a constant hash in order to produce al the wanted methods with a reduced amount of coding.
Here is my code (Please feel free to add additional pointers as I'm new to Ruby):
ENTRY_HASHES = {
"disbursement" => {
:description => TRANSACTION_DESCRIPTIONS[:disbursement]
}
}
public
ENTRY_HASHES.each do |key, value|
def "#{value}?(amount)"
single_entry(
ENTRY_HASHES[:description]
amount
)
@entry.save
end
end
What I'm expecting from the above is something like this (for each of the hashes in ENTRY_HASHES):
def disbursement?(value)
single_entry(
"XXXXX",
amount
)
end
Instead, I'm presented with a syntax error. Any help will be appreciated!