User defined functions in Ruby

Example #1

Ruby Method that does not returns any argument
  1.  
Output
  1. 300

Example #2

Ruby Method that returns 2 arguments
  1.  
Output
  1. 300
  2. 70
  3. 300
  4. 70

Note : Ruby is case sensitive. 'Area' is not equal to 'area'.

Example #3

Ruby program that uses a block. test{..} The yield statement used in the method "test" invokes the code in the block "test" and the yield statement inside the "cal" function invokes the "cal" block. A block is always invoked from a function with the same name as that of the block.
  1. span style="color:#996600;">"Welcome""You are in the function""Addition value is #{@c}""Enter value a :""Enter b:""You are in the block"}
Output
  1. Welcome
  2. You are in the block
  3. You are in the function
  4. You are in the block
  5. Enter value a :
  6. 5
  7. Enter b:
  8. 7
  9. Addition value is 12