Rochambeau for Class Creation in Ruby

There are three ways to create a class method in Ruby.

class Rock

def self.info

“Rock bashes scissors.”

end

end

 

class Paper

class << self

def info

“Paper wraps rock.”

end

end

end

 

class Scissors

end

 

def Scissors.info

“Scissors cut paper.”

end

 

p Rock.info

p Paper.info

p Scissors.info

More Ruby goodness: here, here, and here.

More rochambeau goodness:

RockPaperScissors

(Hat Tip: Emily L.)

About

A typographic, designological, visulicious extravaganza!

Posted in Amusement, Useful Code, Web