ruby - what does nil mean/represent here? -
following simple statements in irb
shell. nil
in 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 return
s 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
Post a Comment