Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • modules in Ruby

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 56
    Comment on it

    For grouping together methods, classes, and constants, we make use of module.
    Modules give you two major benefits:
    1) prevents name clashes.
    2) implement the mixin facility.

    Syntax:

    module Identifier
       statement1
       statement2
       ...........
    end 
    

    Module constants are named with an initial uppercase letter
    Example:

    #!/usr/bin/ruby
    
    # Module defined in trig.rb file
    
    module Trig
       PI = 3.141592654
       def Trig.sin(x)
       # ..
       end
       def Trig.cos(x)
       # ..
       end
    end
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: