Skip to content

Commit

Permalink
Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
msatmod committed Aug 30, 2022
1 parent 6228441 commit 7f798b0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Day 5/Class_Variable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Program for Class Variable i.e. @@x

class Filly
# Initialize our class variables
@@count = 0;
def initialize(l,b)
@length = l
@breadth = b

# @@count = @@count + 1
@@count += 1

end

def printcount()
puts "Number of objects created is: #{@@count}"
end
end

# Create two objects
filly1 = Filly.new(30, 10)
filly2 = Filly.new(20, 5)

# Call class method to print box count
filly1.printcount
filly2.printcount
25 changes: 25 additions & 0 deletions Day 5/Class_variable_with_self_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Program for Class Variable i.e. @@x with self method

class Filly
# Initialize our class variables
@@count = 0;
def initialize(l,b)
@length = l
@breadth = b

# @@count = @@count + 1
@@count += 1

end

def self.printcount
puts "Number of objects created is: #{@@count}"
end
end

# Create two objects
filly1 = Filly.new(30, 10)
filly2 = Filly.new(20, 5)

# Call class method to print box count
Filly.printcount

0 comments on commit 7f798b0

Please sign in to comment.