NameError: when calling lambda from irb
Heng Li <[email protected]> Fri, 6 Dec 2019 19:17:34 -0800
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAKtyc338_2PVZ9gcHJb6BOx8c9c4mXbgCPGpY4AsuXXEu1djrw@mail.gmail.com> |
--===============2037944361==
Content-Type: multipart/alternative; boundary="00000000000040d3d60599149b4d"
--00000000000040d3d60599149b4d
Content-Type: text/plain; charset="UTF-8"
Hi all,
This is my lambda.rb file. first, I run irb -r ./lambda_counter.rb load
file from terminal. then I try call db = new_db.call . I got "NameError:
undefined local variable or method `new_db' for main:Object". i aslo try
load file inside irb, use require 'lambda.rb', it's not working as well.
My os is mac os, ruby is 2.3.3
new_db = lambda do
db ={}
insert = lambda do |artist, album|
db[artist] =album
end
{insert: insert}
end
--00000000000040d3d60599149b4d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi all,<div>This is my lambda.rb file.=C2=A0 first, I run=
=C2=A0 irb -r ./lambda_counter.rb load file=C2=A0 from terminal. then I try=
call db =3D new_db.call . I got "NameError: undefined local variable =
or method `new_db' for main:Object". i aslo try load file inside i=
rb, use require=C2=A0'lambda.rb', it's not working as well.</di=
v><div>My os is mac os, ruby is 2.3.3=C2=A0</div><div><div style=3D"color:r=
gb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,&qu=
ot;Courier New",monospace;font-size:12px;line-height:18px;white-space:=
pre-wrap"><div><span style=3D"color:rgb(156,220,254)">new_db</span> =3D <sp=
an style=3D"color:rgb(220,220,170)">lambda</span> <span style=3D"color:rgb(=
197,134,192)">do</span> </div><div> <span style=3D"color:rgb(156,220,254)"=
>db</span> =3D{}</div><div> <span style=3D"color:rgb(156,220,254)">insert<=
/span> =3D <span style=3D"color:rgb(220,220,170)">lambda</span> <span style=
=3D"color:rgb(197,134,192)">do</span> |<span style=3D"color:rgb(156,220,254=
)">artist</span>, <span style=3D"color:rgb(156,220,254)">album</span>|</div=
><div> db[<span style=3D"color:rgb(156,220,254)">artist</span>] =3Dalbum=
</div><div> <span style=3D"color:rgb(197,134,192)">end</span></div><div> =
{<span style=3D"color:rgb(86,156,214)">insert:</span> <span style=3D"color:=
rgb(156,220,254)">insert</span>}</div><div><span style=3D"color:rgb(197,134=
,192)">end</span></div></div></div></div>
--00000000000040d3d60599149b4d--
--===============2037944361==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--===============2037944361==--