Deal of the Day

Home » Main » Manning Forums » 2007 » Ruby in Practice

Thread: Page 19: printable_attr

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 0 - Pages: 1 Threads: [ Previous | Next ]
vcosby

Posts: 4
From: Bainbridge Island, WA
Registered: 5/22/06
Page 19: printable_attr
Posted: May 2, 2009 2:24 AM
  Click to reply to this thread Reply

I think you want "puts #{attr}" instead; "puts attr.to_s" won't work because attr won't be defined at runtime.

def printable_attribute(attr)
class_eval %{
def p_#{attr}
puts #{attr}
end
}
end

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff