break from a block

E

Eva

SGksCgpIb3cgdG8gYnJlYWsgYSBibG9jayB3aXRoIHN1Y2ggdGhlIG1ldGhvZCBsaWtlIGVhY2g/
CmZvciBleGFtcGxlOgoKRmlsZS5uZXcoImJpZy50eHQiKS5lYWNoIGRvIHxzfAombmJzcDsmbmJz
cDsmbmJzcDsgaWYgcyA9fiAvYWJjZC8KJm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5ic3A7Jm5i
c3A7IHB1dHMgcwombmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsmbmJzcDsgYnJlYWsmbmJz
cDsgIyBpcyB0aGlzIHJpZ2h0PwombmJzcDsmbmJzcDsmbmJzcDsgZW5kCmVuZAoKClRoYW5rcyEK
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

2010/11/24 Eva said:
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. Does it not work when you run it?
 
B

Brian Candler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top