Skip to content

Instantly share code, notes, and snippets.

@undecided
Created March 9, 2011 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save undecided/863152 to your computer and use it in GitHub Desktop.
Save undecided/863152 to your computer and use it in GitHub Desktop.
Shows a simple class implemented in Ruby and Mirah
# Ruby
class Rubyish
def a_method(some_string, some_hash)
@message = some_string
@transform = some_hash
puts @message
end
def another_method
@transform.each_pair do |key, val|
puts @message.gsub(key.to_s, val.to_s)
end
end
end
@a = Rubyish.new
@a.a_method("This looks like ruby", :looks => :smells)
@a.another_method
# Mirah
import java.util.HashMap
class Rubyish
def a_method(some_string:String, some_hash:HashMap)
@message = some_string
@transform = some_hash
puts @message
end
def another_method
@transform.keys.each do |key| # maps down to java's keySet
puts @message.replaceAll(String(key), String(@transform[key]))
end
end
end
@a = Rubyish.new
@a.a_method("This looks like ruby", :looks => :smells)
@a.another_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment