Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:42:26+00:00 2026-06-02T17:42:26+00:00

Is there a practical application to the crazy-ness below? It seems like this is

  • 0

Is there a practical application to the “crazy-ness” below?

It seems like this is a way for ted to always be able to return himself to the world and people will think they are talking to ted who they expect to act a certain way and be a certain age… but he isn’t acting the way he portrays himself and is lying about his age to someone.

What ‘trickery’ is possible when an object is returned and you check on what that object represents and is capable of… but really that object was acting another way and capable of other things before returning.

class Person

  def age
    21
  end

  def who_am_i?
    puts "I am #{self} / #{object_id} and I am #{age} years old"
    self
  end
end


ted = Person.new

def ted.singleton_who_am_i?       

    class << self
      def age
        0
      end
    end

    puts "I am #{self} / #{object_id} and I am #{age} years old"
    self
end

puts ted.who_am_i? == ted.singleton_who_am_i?



>> I am #<Person:0x100138340> / 2148123040 and I am 21 years old
>> I am #<Person:0x100138340> / 2148123040 and I am 0 years old
>> true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:42:27+00:00Added an answer on June 2, 2026 at 5:42 pm

    http://andrzejonsoftware.blogspot.ca/2011/02/dci-and-rails.html

    in DCI, your data model gets different type of behavior based on the context it is used it. Usually it is done with object.extend, but it is pretty much what you are doing above — taking advantage of the metaclass.

    Another example (and probably why things work that way) is the way classes work in ruby. If you say

    class Foo
    end
    

    that is the same thing as saying

    Foo = Class.new
    end
    

    meaning that what you are doing is assigning a new instance of class Class to a constant. When you define a method on that class, you don’t want it applied to all instance of class Class, you only want it on the class you are defining. So when you say

    class Foo
      def self.bar
      end
    end
    

    it is the exact thing as saying

    class Foo
    end
    
    def Foo.bar
    end
    

    which is exactly the same principal as you are talking about in your question

    (sorry if that was unclear)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a practical way for us to slowly evolve a WinForms application to
Is there an easy way to do this? I am testing my networking application
Hopefully two simple questions relating to creating a server application: Is there a theoretical/practical
Is there any practical reason why you would write out a <noscript> tag with
I know that there are more practical ways of going about what I'm trying
Is there such a thing? It is the first time I encountered a practical
Is there any good practice for this? I wish I could solve the problem
is there any best practice way to replace a part of the default template.
I'm currently reading Practical Django Projects and in the Django admin interface there is
I'd like some opinions on the practical implications of moving processing that would traditionally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.