Skip to content

Instantly share code, notes, and snippets.

@leoallen85
Created March 12, 2015 15:05
Show Gist options
  • Select an option

  • Save leoallen85/c0870b838bb2ba8fe716 to your computer and use it in GitHub Desktop.

Select an option

Save leoallen85/c0870b838bb2ba8fe716 to your computer and use it in GitHub Desktop.
Passing methods as arguments with Ruby
def square(integer)
integer * integer
end
[1,2,3].map(&method(:square)) # => [1,4,9]
@leoallen85
Copy link
Copy Markdown
Author

Replicating this behaviour in Javascript:

function square(integer) {
  return integer * integer;
}

[1,2,3].map(square);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment