Delete vars

Hello

is there any method call (metaprogramming?) to remove a var-name (so it doesn't exist any more, undefined, even not nil)

thanks
Opti

Hi Opti,

I just found this:

(quite dated, but I think still valid).

What is your goal with undefining a variable? Why isn't it enough to set
it to nil?

Maybe it makes sense to define the variable in another closure (like the
scope block in the StackOverflow post), so that it is not visible
outside of it?

Cheers,

Paul

0x3B253BC9.asc (5.34 KB)

···

Am 16.11.2016 um 17:09 schrieb Die Optimisten:

Hello

is there any method call (metaprogramming?) to remove a var-name (so
it doesn't exist any more, undefined, even not nil)

thanks
Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hi,
I have some vars (with important contents) in irb, because I need to access these, I tried some test-code in the same session, polluting it with new vars. Now I have so many vars, I should remove the unused, to find the important ones...

Opti

···

On 2016-11-16 17:28, Paul Götze wrote:

Hi Opti,

I just found this:
metaprogramming - Undefine variable in Ruby - Stack Overflow
(quite dated, but I think still valid).

What is your goal with undefining a variable? Why isn't it enough to set
it to nil?

Maybe it makes sense to define the variable in another closure (like the
scope block in the StackOverflow post), so that it is not visible
outside of it?

Cheers,

Paul

Am 16.11.2016 um 17:09 schrieb Die Optimisten:

Hello

is there any method call (metaprogramming?) to remove a var-name (so
it doesn't exist any more, undefined, even not nil)

thanks
Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

IRB allows you to overwrite your variables, so why not just overwrite them to equal something different? Am I understanding you correctly that you want to delete the variables and start fresh?

- Thomas Perkins

···

On Nov 16, 2016, at 4:32 PM, Die Optimisten <inform@die-optimisten.net> wrote:

Hi,
I have some vars (with important contents) in irb, because I need to access these, I tried some test-code in the same session, polluting it with new vars. Now I have so many vars, I should remove the unused, to find the important ones...

Opti

On 2016-11-16 17:28, Paul Götze wrote:
Hi Opti,

I just found this:
metaprogramming - Undefine variable in Ruby - Stack Overflow
(quite dated, but I think still valid).

What is your goal with undefining a variable? Why isn't it enough to set
it to nil?

Maybe it makes sense to define the variable in another closure (like the
scope block in the StackOverflow post), so that it is not visible
outside of it?

Cheers,

Paul

Am 16.11.2016 um 17:09 schrieb Die Optimisten:

Hello

is there any method call (metaprogramming?) to remove a var-name (so
it doesn't exist any more, undefined, even not nil)

thanks
Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I have some vars (with important contents) in irb, because I need to access these, I tried some test-code in the same session, polluting it with new vars. Now I have so many vars, I should remove the unused, to find the important ones...

You can use subsessions in irb:

3559 % irb

x = 42

=> 42

irb
puts x

NameError: undefined local variable or method `x' for main:Object
  from (irb#1):1

y = 24

=> 24

puts y

24
=> nil

jobs

=> #0->irb on main (#<Thread:0x007fc9e10bc8b0>: stop)
#1->irb#1 on main (#<Thread:0x007fc9e20347e8>: running)

fg 0

=> #<IRB::Irb: @context=#<IRB::Context:0x007fc9e182f7a0>, @signal_status=:IN_EVAL, @scanner=#<RubyLex:0x007fc9e184c0a8>>

puts y

NameError: undefined local variable or method `y' for main:Object
  from (irb):3
  from /usr/bin/irb:12:in `<main>'

···

On Nov 16, 2016, at 14:32, Die Optimisten <inform@die-optimisten.net> wrote: