Consider this block of code:
f = File.new('test')
f.each_line { |line|
if line =~ /@b/ then
x = line
end
}
y = x[/<(.*)>/,1]
This is f:
@a <1,2,3>
@b <'whatever'>
@c <['x','y','z']
@d <1.1>
and
Originally, this block of code was working, returning y as 'whatever', but is now throwing this error:
Traceback (most recent call last):
4: from C:/Ruby26-x64/bin/irb.cmd:31:in `<main>'
3: from C:/Ruby26-x64/bin/irb.cmd:31:in `load'
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
1: from (irb):10
NameError (undefined local variable or method `x' for main:Object)
Any suggestions?
P.S.
This is being run directly through irb
@bthenxwill only represent the last one correct?lines = File.foreach('test').grep(/@b/)