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 5af06ef commit 39f6189
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Day 10/Include statement concept/Filly.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Week
First_Day = 'Sunday'

def Week.weeks_in_month
puts "You have 4 weeks in a month"
end

def Week.weeks_in_year
puts "You have 52 weeks in a year"
end
end
24 changes: 24 additions & 0 deletions Day 10/Include statement concept/Mega.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Include Statement

require_relative "Filly.rb"

class Decade
include Week
$no_of_years = 10

def no_of_months
puts "Today is " + Week::First_Day

number = $no_of_years * 12
puts "No. of months in 10 years is " + number.to_s
end
end

d1 = Decade.new

puts Week::First_Day

Week.weeks_in_month
Week.weeks_in_year

d1.no_of_months
32 changes: 32 additions & 0 deletions Day 10/Mixins/Mixins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Module A
module A
def a1
puts "We are in a1 method of Module A"
end

def a2
puts "We are in a2 method of Module A"
end
end

#Module B
module B
def b1
puts "We are in b1 method of Module B"
end

def b2
puts "We are in b2 method of Module B"
end
end

class Sample
include A
include B
end

s = Sample.new
s.a1
s.a2
s.b1
s.b2
17 changes: 17 additions & 0 deletions Day 10/Require & Require Relative/Class_in_modules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# class in module

module Mymodule
class TestClass

def initialize
puts "TestClass object created"
end

def mymethod
puts "It is a user defined method"
end
end
end

myobject = Mymodule::TestClass.new
myobject.mymethod
29 changes: 29 additions & 0 deletions Day 10/Require & Require Relative/Modules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#code for module

module Trig
PI = 3.14

def Trig.sinfunction(x)
puts Math.sin(x)
end
def Trig.cosfunction(x)
puts Math.cos(x)
end
end

module Moral
Very_bad = 0
Bad = 1
def Moral.sinfunction(badnesslevel)
if (badnesslevel == 0)
puts 'You are very bad'
else
puts 'You are just bad'
end
end
end

puts Trig::PI
Trig.sinfunction(0)

Moral.sinfunction(Moral::Bad)
11 changes: 11 additions & 0 deletions Day 10/Require & Require Relative/Require_example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative 'classinmodules.rb'
require_relative 'modules.rb'

myobject = Mymodule::TestClass.new
myobject.mymethod

puts Trig::PI

Trig.sinfunction(0)

Moral.sinfunction(Moral::Bad)
13 changes: 13 additions & 0 deletions Day 10/Require & Require Relative/Require_relative_example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$LOAD_PATH << '.'

require 'classinmodules.rb'
require 'modules.rb'

myobject = Mymodule::TestClass.new
myobject.mymethod

puts Trig::PI

Trig.sinfunction(0)

Moral.sinfunction(Moral::Bad)

0 comments on commit 39f6189

Please sign in to comment.