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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:40:36+00:00 2026-06-04T12:40:36+00:00

I am calling the RestClient::Resource#get(additional_headers = {}, &block) method multiple times with the same

  • 0

I am calling the RestClient::Resource#get(additional_headers = {}, &block) method multiple times with the same block but on different Resources, I was wondering if there is a way to save the block into a variable, or to save it into a Proc convert it into a block each time.

Edit:

I did the following:

resource = RestClient::Resource.new('https://foo.com')
redirect  =  lambda do  |response, request, result, &block|
  if [301, 302, 307].include? response.code
     response.follow_redirection(request, result, &block)
   else
      response.return!(request, result, &block)
   end
end
@resp = resource.get (&redirect)

I get: Syntax error, unexpected tAMPER

  • 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-04T12:40:38+00:00Added an answer on June 4, 2026 at 12:40 pm
    foo = lambda do |a,b,c|
       # your code here
    end
    
    bar.get(&foo)
    jim.get(&foo)
    jam.get(&foo)
    

    Placing an ampersand in front of an item in a method call, e.g. a.map!(&:to_i) calls the to_proc method on that object and passes the resulting proc as a block. Some alternative forms of defining your re-usable block:

    foo = Proc.new{ |a,b,c| ... }
    foo = proc{ |a,b,c| ... }
    foo = ->(a,b,c){ ... }
    

    If you are calling a method with a block and you want to save that block for re-use later, you can do so by using an ampersand in the method definition to capture the block as a proc parameter:

    class DoMany
      def initialize(*items,&block)
        @a = items
        @b = block # don't use an ampersand here
      end
      def do_first
        # Invoke the saved proc directly
        @b.call( @a.first )
      end
      def do_each
        # Pass the saved proc as a block
        @a.each(&@b)
      end
    end
    
    d = DoMany.new("Bob","Doug"){ |item| puts "Hello, #{item}!" }
    
    d.do_first
    #=> Hello, Bob!
    
    d.do_each
    #=> Hello, Bob!
    #=> Hello, Doug!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
Calling index.php?pConta=1&pDataInicial=01-01-2000&pDataFinal=31-12-2000 I get this notices: [08-Oct-2009 17:30:35] PHP Notice: Undefined index: pConta in
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
Calling MyPanel.Panel1.Hide(); or MyPanel.Panel2.Hide(); simply hides the controls inside the panel... but I want
Calling multiMax() at the bottom of the code block we pass in 4 arguments.
I calling multiple function on page load in my asp.net web application. All function
Calling a Lua function from C is fairly straight forward but is there a
Calling std::count_if(vec.begin(), vec.end(), std::bind2nd(std::ptr_fun(foo), 17)) works fine with bool foo(int, int), but I can't
Calling this method: public static @Nonnull <TV, TG extends TV> Maybe<TV> something(final @Nonnull TG
Calling an asp.net mvc3 controller method which returns the results fine (list of an

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.