ruby - what does nil mean/represent here? -


following simple statements in irb shell. nilin output mean ? why accompany print statement in if block ?

irb(main):062:0> if(x==20 && y==30) irb(main):063:1> print("if statement working !") irb(main):064:1> else irb(main):065:1* print("else statement working !!") irb(main):066:1> end if statement working !=> nil # nil represent here ? 

in ruby, expressions return values, if it's nil. blocks , methods return value of last expression evaluated. there many ways use effectively. example, reason explicit returns not used. also, can this:

print if x == 20 && y == 30   'if statement working!' else   'else statement working!' end 

regarding example: in addition printing string instructed, irb display value received if-else blocks. since print returns nil, both branches return same value.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -