Re: NameError: when calling lambda from irb
Heng Li <[email protected]> Fri, 6 Dec 2019 21:21:01 -0800
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAKtyc31=G3axco=U6VjaGMu9DcNeqh_qGLMUe556h-6njaPrCg@mail.gmail.com> |
--===============1361135071== Content-Type: multipart/alternative; boundary="000000000000d811890599165427" --000000000000d811890599165427 Content-Type: text/plain; charset="UTF-8" Thanks, Raj. I tried your suggestion. it return the the same error. I'm in the directory where lambda.rb file is located. so it look like not the issue of the file path -Heng On Fri, Dec 6, 2019 at 8:48 PM Raj Sahae <[email protected]> wrote: > 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> >> > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > --000000000000d811890599165427 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Thanks, Raj. I tried your suggestion. it return the the sa= me error. I'm in the directory where lambda.rb file is located. so it l= ook like not the issue of the file path=C2=A0<div><br></div><div>-Heng=C2= =A0=C2=A0</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class= =3D"gmail_attr">On Fri, Dec 6, 2019 at 8:48 PM Raj Sahae <<a href=3D"mai= lto:[email protected]">[email protected]</a>> wrote:<br></div><blockqu= ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px= solid rgb(204,204,204);padding-left:1ex"><div dir=3D"auto"><div>the proble= m 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 dir=3D"auto">- Raj</div></div><br><div cl= ass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Dec 6, 20= 19, 7:18 PM Heng Li <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:<br></div><blockquote cl= ass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid= rgb(204,204,204);padding-left:1ex"><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 f= ile=C2=A0 from terminal. then I try call db =3D new_db.call . I got "N= ameError: undefined local variable or method `new_db' for main:Object&q= uot;. i aslo try load file inside irb, use require=C2=A0'lambda.rb'= , it'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,212,212);background-color:rgb(30,= 30,30);font-family:Menlo,Monaco,"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 <span style=3D"color:rgb(220,220,170)">lamb= da</span> <span style=3D"color:rgb(197,134,192)">do</span> </div><div> <sp= an 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:r= gb(156,220,254)">album</span>|</div><div> db[<span style=3D"color:rgb(15= 6,220,254)">artist</span>] =3Dalbum</div><div> <span style=3D"color:rgb(19= 7,134,192)">end</span></div><div> {<span style=3D"color:rgb(86,156,214)">i= nsert:</span> <span style=3D"color:rgb(156,220,254)">insert</span>}</div><d= iv><span style=3D"color:rgb(197,134,192)">end</span></div></div></div></div= > <br> Unsubscribe: <mailto:<a href=3D"mailto:[email protected]" = rel=3D"noreferrer" target=3D"_blank">[email protected]</a>?su= bject=3Dunsubscribe><br> <<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>><br> </blockquote></div></div></div> <br> Unsubscribe: <mailto:<a href=3D"mailto:[email protected]" = target=3D"_blank">[email protected]</a>?subject=3Dunsubscribe= ><br> <<a href=3D"http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk= " rel=3D"noreferrer" target=3D"_blank">http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-talk</a>><br> </blockquote></div> --000000000000d811890599165427-- --===============1361135071== 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> --===============1361135071==--