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

  • Home
  • SEARCH
  • 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 42647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:22:15+00:00 2026-05-10T15:22:15+00:00

For a project I am working on in ruby I am overriding the method_missing

  • 0

For a project I am working on in ruby I am overriding the method_missing method so that I can set variables using a method call like this, similar to setting variables in an ActiveRecord object:

Object.variable_name= 'new value'

However, after implementing this I found out that many of the variable names have periods (.) in them. I have found this workaround:

Object.send('variable.name=', 'new value')

However, I am wondering is there a way to escape the period so that I can use

Object.variable.name= 'new value'

  • 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. 2026-05-10T15:22:16+00:00Added an answer on May 10, 2026 at 3:22 pm

    Don’t do it!

    Trying to create identifiers that are not valid in your language is not a good idea. If you really want to set variables like that, use attribute macros:

    attr_writer :bar attr_reader :baz attr_accessor :foo 

    Okay, now that you have been warned, here’s how to do it. Just return another instance of the same class every time you get a regular accessor, and collect the needed information as you go.

    class SillySetter   def initialize path=nil     @path = path   end    def method_missing name,value=nil     new_path = @path ? '#{@path}.#{name}' : name     if name.to_s[-1] == ?=       puts 'setting #{new_path} #{value}'     else       return self.class.new(path=new_path)     end   end end  s = SillySetter.new s.foo = 5              # -> setting foo= 5 s.foo.bar.baz = 4      # -> setting foo.bar.baz= 4 

    I didn’t want to encourage ruby sillyness, but I just couldn’t help myself!

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Ninject 2.0 has this capability: Bind<IMyService>().To<MyServiceA>().Named('Data'); Bind<IMyService>().To<MyServiceB>().Named('SomethingElse'); kernel.Get<IMyService>('Data'); // will… May 11, 2026 at 12:58 pm
  • added an answer If you are not particular about testing in your machine,… May 11, 2026 at 12:58 pm
  • added an answer You probably want to look at the Instant Client. You… May 11, 2026 at 12:58 pm

Related Questions

For a project I am currently working on, I am interested in allowing users
I am working on a little pinball-game project for a hobby and am looking
I am working on a project that is going to use CouchDB for flexible
I am working on a Java project using Netbeans for the first time. I
I would like to do the equivalent off this (ruby code) in python for
I have worked a bit with Django and I quite like its project/applications model
First a bit of background. I have been working on the MS platform for
In the installation documentation to RoR it mentions that there are many limitations to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.