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 6737003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:11:49+00:00 2026-05-26T11:11:49+00:00

How do I pass the parameter name in the following case..the name is being

  • 0

How do I pass the parameter name in the following case..the name is being is evaluated before being passed to class_eval

 
class Foo

end

Foo.class_eval %Q{
def hello(name)
 p "hello #{name}"
end
}


Sorry about not giving the entire scenario…
I just wanted to add a instance method dynamically to a class and that method should be able to take arguments…
the above code would not compile complaining that the name is not defined as local variable when executing in irb..

Thanks

  • 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-05-26T11:11:50+00:00Added an answer on May 26, 2026 at 11:11 am

    The other answers are the “right” answer, but you could also just skip interpolating inside the p call:

    Foo.class_eval %Q{
      def hello(name)
        p "hello \#{name}"
      end
    }
    

    I thought you wanted to change the actual parameter name (possibly useful for completion or when using Pry on dynamic methods), here assuming it’s in a global, but could also be passed into a method doing the class_eval:

    Foo.class_eval %Q{
      def hello(#{$argname})
        p "hello \#{$argname}"
      end
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ERROR: unknown web method DoIt Parameter name: methodName I'm trying to pass a date
I have a get-parameter with name controller . When I try to pass it
I want to pass the name of a field as a parameter to a
I have pulled last uploaded image using following code class categoryForm(forms.Form): name = forms.CharField(widget=forms.TextInput(attrs={'class':'box'}),max_length=32,label='Category',required=True)
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
name_iexact keyword is a parameter we can pass to filter function in django.model. Can
I would like to pass {id:1, name:stackoverflow, parameter2:false, parameter3:true} To my action public JsonResult
Possible Duplicate: pass parameter in g:remoteLink as result of javascript function I am trying
I'm trying to pass parameter from python page to another through the URL,this parameter(key
My Controller :-ForumController Action :Topic ViewPage to pass parameter is <%= Html.ActionLink(Topic, Topic, Forum,

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.