Trying to understand method calls in a class body. Fundamentally, why doesn't this work?

Good morning


On Fri, Dec 05, 2014 at 08:46:48PM -0500, Jorge Colon wrote:

Ok. That makes sense. Out of pure curiosity, is there any "hacky" way to call
instance methods in a class context?

class Thing
  def initialize()
    puts "baeh"

  def do_something(arg = nil)
    puts "Doo! " << arg.to_s

  def self::do_it()'Did it!')

# dumbly overwrite the previous class-definition
class Thing

# or explicitly call a method on the defined class



Senior Software Architect/Owner
2UP Media
c: 407.489.2677

PHP Zend Certified Engineer

On Dec 5, 2014, at 8:37 PM, Bryce Kerley wrote:

        On Dec 5, 2014, at 20:34, Jorge Colon <> wrote:


        Since I'm essentially passing in an instance "dude" to the singleton
        class, is the class body still in the context of a class and NOT the
        instance "dude”?


    [3] pry(main)> puts dude.inspect
    #<struct name="John Doe">
    => nil
    [4] pry(main)> class << dude
    [4] pry(main)* puts inspect
    [4] pry(main)* end

GnuPG/OpenPGP 4096R/3216CF02 2013-11-15 [expires: 2015-11-15]
Michael Uplawski (privat) <>
sub 4096R/2751C550 2013-11-15 [expires: 2015-11-15]
[Next key will use elliptic-curve algorithm! Get GnuPG!!]

This doesn't overwrite anything, nor is it dumb. It is just reopening a class.


On Dec 6, 2014, at 00:59, Michael Uplawski <> wrote:

# dumbly overwrite the previous class-definition
class Thing