Re: NameError: when calling lambda from irb

Raj Sahae <[email protected]> Fri, 6 Dec 2019 20:47:35 -0800
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAJHnM_5H2nDULw9wwMXrRPu32s3qBuxeLmORtVMm2Nq00c+cRw@mail.gmail.com>
--===============0300720149==
Content-Type: multipart/alternative; boundary="0000000000002f3c6d059915dd0d"

--0000000000002f3c6d059915dd0d
Content-Type: text/plain; charset="UTF-8"

the problem is your load path.  try

irb -I $PWD -r lamba

- Raj

On Fri, Dec 6, 2019, 7:18 PM Heng Li <[email protected]> wrote:

> 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
>
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>

--0000000000002f3c6d059915dd0d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div>the problem is your load path.=C2=A0 try<div dir=3D"=
auto"><br></div><div dir=3D"auto">irb -I $PWD -r lamba<br><br><div data-sma=
rtmail=3D"gmail_signature" dir=3D"auto">- Raj</div></div><br><div class=3D"=
gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Dec 6, 2019, 7:1=
8 PM Heng Li &lt;<a href=3D"mailto:[email protected]">techitao.henry=
@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">Hi all,<div>This is my lambda.rb file.=C2=A0 first, I run=C2=A0 ir=
b -r ./lambda_counter.rb load file=C2=A0 from terminal. then I try call db =
=3D new_db.call . I got &quot;NameError: undefined local variable or method=
 `new_db&#39; for main:Object&quot;. i aslo try load file inside irb, use r=
equire=C2=A0&#39;lambda.rb&#39;, it&#39;s not working as well.</div><div>My=
 os is mac os, ruby is 2.3.3=C2=A0</div><div><div style=3D"color:rgb(212,21=
2,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,&quot;Courie=
r New&quot;,monospace;font-size:12px;line-height:18px;white-space:pre-wrap"=
><div><span style=3D"color:rgb(156,220,254)">new_db</span> =3D <span 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</spa=
n> =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"col=
or:rgb(197,134,192)">do</span> |<span style=3D"color:rgb(156,220,254)">arti=
st</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>
<br>
Unsubscribe: &lt;mailto:<a href=3D"mailto:[email protected]" =
target=3D"_blank" rel=3D"noreferrer">[email protected]</a>?su=
bject=3Dunsubscribe&gt;<br>
&lt;<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk=
" rel=3D"noreferrer noreferrer" target=3D"_blank">http://lists.ruby-lang.or=
g/cgi-bin/mailman/options/ruby-talk</a>&gt;<br>
</blockquote></div></div></div>

--0000000000002f3c6d059915dd0d--

--===============0300720149==
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>

--===============0300720149==--