Ruby learning-varaible

Source: Internet
Author: User
1 # global variable 2 $ global_variable = 103 class class14 def print_global () 5 puts "global variable in class1 is # {$ global_variable}" 6 end7 end8 class1obj = class1.new9 class1obj. print_global ()
1 # instance variable 2 Class Customer 3 def initialize (ID, name, ADDR) 4 @ cust_id = ID 5 @ cust_name = Name 6 @ cust_addr = ADDR 7 end 8 def display_detalis 9 puts "Customer ID #{@ cust_id}" 10 puts "customer name #{@ cust_name} "11 puts" customer ADDR # {@ cust_addr} "12 end13 end14 cust1 = customer. new ("1", "John", "wisdom") 15 cust1.display _ detaching
1 # class variable 2 Class Customer 3 @ no_of_mers MERs = 0 4 def initialize (ID, name, ADDR) 5 @ cust_id = ID 6 @ cust_name = Name 7 @ cust_addr = ADDR 8 end 9 def display_details () 10 puts "Customer ID # {@ cust_id}" 11 puts "customer name # {@ cust_name}" 12 puts "customer ADDR # {@ cust_addr}" 13 end14 def total_no_of_mers MERs () 15 @ no_of_mers MERs + = 116 puts "totla Number of MERs: # {@@ no_of_customers}" 17 end18 end19 cust1 = customer. new ("1", "John", "wisdom") 20 cust2 = customer. new ("2", "Poul", "new") 21 22 cust1.total _ no_of_customers23 cust2.total _ no_of_mers MERs

 

Ruby learning-varaible

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.