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

The Archive Base Latest Questions

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

I am following the interactive tutorials on rubymonk.com and have just started with lambda’s

  • 0

I am following the interactive tutorials on rubymonk.com and have just started with lambda’s which I feel I grasp reasonably well, however I am a bit lost with this code:

1  def with_names(fn)
2   result = []
3   [ ["Christopher", "Alexander"],
4     ["John", "McCarthy"],
5     ["Joshua", "Norton"] ].each do |pair|
6       result << fn.call(pair[0], pair[1])
7   end
8   result
9  end
10  l = lambda { |first_name, last_name| "#{first_name} #{last_name}" }
11  with_names(l)

Are the names entered between line 3’s first [ and line 5’s ] held in an array or a hash? My understanding is that they are a hash of arrays and that when calling `.each do |pair| we are iterating through each array in the hash, is this correct? In the next piece of code on line 6:

result << fn.call(pair[0], pair[1])

I believe that we are pushing each array element into the results array, although I’m not sure exactly how this code works especially the fn.call part as I believe the (pair[0], pair[1]) part is simply pulling the data in the index location of each array passed through the block. A clear explanation of what is going on here would be much appreciated, I feel I am almost there with it. 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-06-04T02:06:37+00:00Added an answer on June 4, 2026 at 2:06 am

    Are the names entered between line 3’s first [ and line 5’s ] held in an array or a hash?

    The name strings are held in arrays, all of which are contained in another “master” array. On looping through the “master” array, its elements (namely, ["Christopher", "Alexander"], etc.) will be passed to the block succeeding the each call.


    In fn.call(pair[0], pair[1]), the lambda passed to the function is called with two arguments: the first and last name provided by the each iteration. This lambda is assumed to return some value. In this case, the lambda returns a concatenated string, so the expression partially evaluates to something like this:

    result << "Christopher Alexander"
    

    From here, the << overloaded operator indicates that the right operand should be pushed onto the left operand (an array).

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

Sidebar

Related Questions

I have made the following webpage for generating interactive todo lists: http://robert-kent.com/todo/todo.php Basically, the
I'm following this tutorial on making an animation like IKEA: http://static.buildinternet.com/live-tutorials/interactive-picture/index.html The issue I'm
i have the following in my .emacs file(thanks to SOer nikwin), which evaluates the
So following http://www.techotopia.com/index.php/Creating_an_Interactive_iOS_4_iPhone_App , I'm doing the tutorial in a tabbed application template which
I have the following custom function in ~/.emacs: (defun xi-rgrep (term) (grep-compute-defaults) (interactive sSearch
I have the following elisp: (require 'widget) (eval-when-compile (require 'wid-edit)) (defun testit () (interactive)
If using Tcl in interactive mode , in which I input the following: set
I have the following command: ruby SaveAllDatabases.rb 192.168.0.15 1024 -r #0-D --non-interactive It's a
I have the following Template Haskell code in my module, which is part of
I have an Emacs command like following: (defun query-lisp (word) (interactive sType a word

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.