Skip to content

Instantly share code, notes, and snippets.

@chad
Created January 19, 2011 20:51
Show Gist options
  • Save chad/786845 to your computer and use it in GitHub Desktop.
Save chad/786845 to your computer and use it in GitHub Desktop.
class MorseEncoder
TRANSLATIONS = {
:a => "._",
:b => "_...",
:c => "_._.",
:d => "_..",
:e => "."
}
def method_missing(m, *args)
@translations.unshift TRANSLATIONS[m]
end
def encode(&block)
@translations = []
instance_eval(&block)
@translations.join(" ")
end
end
morse = MorseEncoder.new
puts morse.encode { b e a d }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment