eigenclass Questions

3

Solved

I m having trouble understanding the concept of eigenclass or singleton class in ruby. I read a lot that the eigenclass is a class's class. That doesn't make sense to me as for me a class's class i...
Idun asked 22/4, 2020 at 17:23

3

Solved

In Ruby, the method puts is a singleton method of the Kernel module. Normally, when a module is included or extended by another module, the module (but not its singleton class) is added to the inh...
Breland asked 10/9, 2019 at 14:15

0

I've been looking for a natural way to implement state-dependent behaviour (state machines) in Python objects. The goal was for objects to have a small number of states, or "mutually orthogonal" as...
Crossroad asked 6/5, 2019 at 15:7

3

Solved

Let's open class Module and add a method to it: class Module def foo puts "phew" end end I can call this method by doing this, Class.foo which is understandable because class of Class...
Henke asked 18/3, 2013 at 11:25

6

Solved

What does class << self do in Ruby?
Humber asked 24/3, 2010 at 3:2

4

Solved

Are class methods and methods in the eigenclass (or metaclass) of that class just two ways to define one thing? Otherwise, what are the differences? class X # class method def self.a "a" end...
Consols asked 18/11, 2010 at 16:18

1

This part works: class Example1 @@var1= "var1 in the Example1" def get_var1 @@var1 end end example1 = Example1.new example1.get_var1 # => "var1 in the Example1" but if I try eigencl...
Shawnee asked 1/7, 2014 at 12:59

3

Solved

In Ruby, getting the eigenclass of a class Foo is a simple as eigenclass = class << Foo; self; end #=> #<Class:Foo> eigenclass = Foo.singleton_class #2.1.0 #=> #<Class:Foo>...
Gery asked 1/2, 2014 at 21:19

2

Solved

I understand the regular method lookup path i.e. class, superclass/module, all the way up to BasicObject. I thought it was true for singleton version of the chain also but doesn't seem the case whe...
Carioca asked 7/11, 2012 at 11:55

1

Solved

I have defined a module Vehicle like such module Vehicle class <<self def build end private def background end end end A call to Vehicle.singleton_methods returns [:build]. How c...
Crotchety asked 27/8, 2012 at 2:51

4

Solved

I was trying to limit the instantiation of a class to just a single one(without using singleton) but i couldn't. I tried with class variables (@@) but without luck. I googled it and came across thi...
Legit asked 8/1, 2010 at 4:48

3

Getting a list of all modules is easy in Ruby: ObjectSpace.each_object(Module).to_a However, is it possible to get a list of all eigenclasses (also known as singleton classes or metaclasses)? Or...
Camilla asked 19/10, 2011 at 3:50

2

Solved

I am currently experimenting with Ruby and Rails, and I've hit a few sections in tutorials and books about metaprogramming. Many mention that it is an essential component of Ruby but they don't rea...
Ephrayim asked 23/8, 2011 at 7:17

3

Solved

I've missed the memo somewhere, and I hope you'll explain this to me. Why is the eigenclass of an object different from self.class? class Foo def initialize(symbol) eigenclass = class << ...
Rowdy asked 27/10, 2009 at 13:31
1

© 2022 - 2024 — McMap. All rights reserved.