Ruby
- Functional Ruby
January 31, 2019

- Eigenclass in Ruby
April 8, 2016
References:
- http://www.integralist.co.uk/posts/eigenclass.html
- https://gist.github.com/Integralist/bb8760d11a03c88da151
When creating singleton methods (i.e. def self.foo) Ruby will create an anonymous class to hold these methods. The anonymous class then assumes the role of the object’s class and the original class is re-designated as the superclass of that anonymous class (Eigenclass).
privateis actually a methodprivatemethod only changes the visibility of instance methodsClass methods on the other hand are instance methods of the Eigenclass
- Ampersand Operator in Ruby
April 4, 2016
This is how a function call with an ampersand looks like:
1some_function(&an_object)When used as shown above, the & operator induces a call to to_proc on the argument, and passes the resulting Proc object (explained in the box below) as a block to the method.
What’s a Proc? A Proc object encapsulates a function or a block in a way that can be passed around in a variable. We can initialize a Proc with a block like this: