Hi,
How to break a block with such the method like each?
for example:
File.new(“big.txt”).each do |s|
if s =~ /abcd/
puts s
break # is this right?
end
end
Thanks!
Hi,
How to break a block with such the method like each?
for example:
File.new(“big.txt”).each do |s|
if s =~ /abcd/
puts s
break # is this right?
end
end
Thanks!
Yes that’s right - minus all the 's
irb makes it very easy to experiment with the language.
irb(main):001:0> (1…10).each { |x| break if x > 4; puts x }
1
2
3
4
=> nil
2010/11/24 Eva [email protected]
Hi,
How to break a block with such the method like each?
for example:File.new(“big.txt”).each do |s|
if s =~ /abcd/
puts s
break # is this right?
end
endThanks!
Yes. Does it not work when you run it?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs