Call String.instance_method to get a method pointer : Method Pointer « Method « Ruby






Call String.instance_method to get a method pointer



umeth = String.instance_method(:length)

m1 = umeth.bind("cat")
m1.call                         # 3

m2 = umeth.bind("caterpillar")
m2.call                         # 11

 








Related examples in the same category

1.Use method from String class to map a method from String to a method pointer
2.Get pointer to a method in Fixnum
3.Assign method pointer to another method