0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます。
( from python 3.7 to ruby 2.7 )

lambda (Python)

    _identity = lambda x, **kw: x

いわゆる無名関数ですね。

lambda (Ruby)

  _identity = ->(x, **kw) { x }
  # or
  _identity = lambda { |x, **kw| x }

lambdaProcの違いの一つに引数の数が違っている場合があげられますが、可変長引数を使用するとエラーにならない様です。

identity2 = ->(x, **kw) { x }
puts identity2.call(2)

# 2

identity1 = ->(x, kw) { x }
puts identity1.call(1)

main.rb:5:in `block in <main>': wrong number of arguments (given 1, expected 2) (ArgumentError)

メモ

  • Python の lambda を学習した
  • 道のりは遠そう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?