IronRuby and hashes in metaprogramming

by DotNetNerd 29. June 2010 19:39

This will probably be one of the shortest blogposts I'll ever write, and probably the one with the least amount of code - besides an occational rant. The reason is that like pictures sometimes say more than a 1000 words, so does elegant code.

module MyModule
class MyClass
def write_stuff text
puts text
end
end
end

m = MyModule::MyClass.new
actions = {:write_stuff => "Hello action packed world!"}
actions.each {|key, value| m.method(key).call(value) }

It might just be me who is weird - but I think this way of doing eg. a strategy pattern is pretty cool.

Tags:

Who am I?

My name is Christian Holm Diget, and I work as an independent consultant, in Denmark, where I write code, give advice on architecture and help with training. On the side I get to do a bit of speaking and help with miscellaneous community events.

Some of my primary focus areas are code quality, programming languages and using new technologies to provide value.

Microsoft Certified Professional Developer

Microsoft Most Valuable Professional

Month List

bedava tv izle