RudyGems

Matthew Rudy Jacobs
see me swim
Github
see some of my code
Thought Sauce
Hire me in Hong Kong

Even more Ruby in Chinese

I realised I can write even more Ruby in Chinese.

The only gotchas are;

  • don’t attempt to use Chinese punctuation (”‘=+-,。)
  • it doesn’t recognise Chinese as uppercase, so you can’t start a class or Constant name with a chinese character

So here is my code.

# encoding: utf-8

class C动物

  def initialize(名字)
    @名字 = 名字
  end
  attr_reader :名字

  def 朋友?(别的)
    true
  end

  def 吃了?
    false
  end

end

class C狗 < C动物
  
  def 朋友?(别的)
    !别的.is_a?(C马泰)
  end

end

class C人 < C动物
end

class C马泰 < C人
  
  def 吃了?(别的)
    别的.is_a?(C狗)
  end

end

我=C马泰.new("马泰")
puts "我的名字是#{我.名字}"
她=C人.new("张学敏")
puts "她的名字是#{她.名字}"

狗=C狗.new("阿财")
puts "狗的名字是#{狗.名字}"

puts "狗是我的朋友吗?#{我.朋友?(狗)}"
puts "我是狗的朋友吗?#{狗.朋友?(我)}"

puts "狗吃了我吗?#{狗.吃了?(我)}"
puts "我吃了狗吗?#{我.吃了?(狗)}"

See the full gist at https://gist.github.com/711563

Maybe I should write a plugin for rails.