-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
Day 10/Require & Require Relative/Require_relative_example.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |