ruby - Function executed without being called -


i have function func, , executes automatically; have never called it.

begin {   print "start" } *data = gets; test = true in 0...data.length   if i==0     print data[i]   end   if i==0 , !test     print "test"   else     print "uu"   end end end {   print "end" }  def func()   print "test1"   yield   print "test2" end  func {   print "func block" } 

output of above code:

startuserinput userinput uutest1func blocktest2end 

i don't want function executed when call it. can't use function parameters due automatic calling.

func {} calling function func.

why? {} accepting block. can think of blocks arguments.

see how begin , end works.

they got called parameters passed in (via blocks).


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -