fork download
  1. #!/usr/bin/env ruby
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Twitter / @ka_
  5. # 今回の響チャレンジは,Ruby で if 「文」や三項演算子などなど…を用いずに if メソッドを実装!だぞ!
  6. # http://t...content-available-to-author-only...r.com/ka_/status/308062747252383745
  7.  
  8. def IF(condition, trueresult, falseresult)
  9. [trueresult, falseresult][(!!condition).inspect.length - 4]
  10. end
  11.  
  12. puts IF("Ganaha".index("i"), "Found", "Not found")
  13. puts IF("Hibiki".index("i"), "Found", "Not found")
Success #stdin #stdout 0.01s 7408KB
stdin
Standard input is empty
stdout
Not found
Found