Re: NameError: when calling lambda from irb
Xavier Noria <[email protected]> Sat, 7 Dec 2019 11:40:49 +0100
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAM=Ycdhp1F8ydqRZo019S-YU+gHdq0dQ4aL2oR4HX6CxbjGd=g@mail.gmail.com> |
--===============1450691100== Content-Type: multipart/alternative; boundary="000000000000d5c7e705991acdb6" --000000000000d5c7e705991acdb6 Content-Type: text/plain; charset="UTF-8" Variables at the top-level are local to the file. If you `require` or `load` the file, the variable won't leak to the caller scope. The parent code, in particular, can have its own `new_db` variable and do not worry about loaded files messing with it. That is the point of the file scope. You need to define that logic in some global place, using a global variable, a constant, method in a module defined normally (not my_module = Module.new) , etc. The choice depends on the purpose of that file. --000000000000d5c7e705991acdb6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Variables at the top-level are local to the file. If you `= require` or `load` the file, the variable won't leak to the caller scop= e. The parent code, in particular, can have its own `new_db` variable and d= o not worry about loaded files messing with it. That is the point of the fi= le scope.<div><br></div><div>You need to define that logic in some global p= lace, using a global variable, a constant, method in a module defined norma= lly (not my_module =3D Module.new) , etc. The choice depends on the purpose= of that file.</div><div><br></div></div> --000000000000d5c7e705991acdb6-- --===============1450691100== 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> --===============1450691100==--