wickedcoolthoughts
Friday, December 14, 2007
  Singleton Method Ruby vs Java


I thought this was cool

// This was the closest i could get in java.
// still confused about the terminology 'SingletonMethod'
public class SingletonMethodJava {

void theOnlyMethod(){
System.out.println("theOnlyMethod");
}

public static void main(String[] args){

new SingletonMethodJava(){
void addedOneMoreMethod(){
System.out.println("addedOneMoreMethod");
}
}.addedOneMoreMethod();
}
}


But isn't this cooler ?


class SingletonMethodRuby

def theOnlyMethod
puts "theOnlyMethod";
end
end

singleton_method = SingletonMethodRuby.new

def singleton_method.addedOneMoreMethod
puts "addedOneMoreMethod";
end

singleton_method.addedOneMoreMethod

 
Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

My Photo
Name:
Location: India

I am passionate about making Better Software Solutions,that helps businesses to stay agile, by applying Agile,Lean and Systems Thinking principles. Also I grow coffee,spices and in general has big interest in pesticide free food!

Archives
December 2007 / January 2008 / February 2008 / March 2008 / June 2011 /


Powered by Blogger

Subscribe to
Posts [Atom]