Upload
linh-bui
View
92
Download
2
Embed Size (px)
Citation preview
Ruby methods Featuring: cats
public class Cat { public static int getNumLegs() { return 4; } public void eat() { System.out.println("om nom nom"); } public static void main(String[] args) { Cat happyCat = new Cat(); happyCat.eat(); }}
class Cat def self.number_of_paws # identity crisis 4 endend
class Cat; end
happy_cat = Cat.new
def happy_cat.bark puts "woof" end
happy_cat.bark # woof
class Cat; end
happy_cat = Cat.new
class << happy_cat def bark puts "woof" endend
class SomeClass class << self def class_method_1 end
def class_method_2 end endend
class Cat def self.number_of_paws 4 endend
module CatStuff def eat puts "eating the cat way" endend
class Cat include CatStuffend
module CatClassStuff def num_of_legs 4 endend
class Cat extend CatClassStuffend
module CatStuff def bark puts "woof" endend
class Cat; end
happy_cat.include(CatStuff)
module CatStuff def bark puts "woof" endend
class Cat; end
happy_cat.extend(CatStuff)happy_cat.bark# woof
class C; end
C.class_eval do def d puts "d" endend
C.dC.new.d
class C; end
C.instance_eval do def d puts "d" endend
C.dC.new.d