Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions Svyryda_Homework2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Index: lib/topics/state_and_behaviour.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/topics/state_and_behaviour.rb (date 1497217375000)
+++ lib/topics/state_and_behaviour.rb (revision )
@@ -1,40 +1,29 @@
# frozen_string_literal: true

# exercise state and behaviour
-class Newspaper
- def every_day
- "Actual newspaper is publised every day"
+module StateAndBehaviour
+
- end
+end
+class Car
+ attr_accessor :year,:color,:model,:current_speed
+
+
+def initialize (car_attributes)
+ @year=car_attributes[:year] || 2015
+ @color=car_attributes[:color] || 'purple'
+ @model=car_attributes[:model] || 'skyline'
+ @current_speed = car_attributes[:current_speed] = 8
-end
+ end
-class Magazine
- def every_week
- "Fresh magazine is published every week"
+
+def speed_up (speed_is_raising)
+ @current_speed+=speed_is_raising
- end
+end
+
+def push_break (speed_decrease)
+ @current_speed-=speed_decrease
end
-class Book
- def writer_under_inspiration
- "Readers are waiting for bestseller"
- end
-end

-module StateAndBehaviour
- class Print_Edition
- attr_reader :periodicity
- def initialize (periodicity)
- @periodicity =periodicity
+def self.default_car
+ Car.new(default_car)
- end
+end
- def periodicity
- case periodicity
- when Newspaper
- periodicity.every_day
- when Magazine
- periodicity.every_week
- when Book
- periodicity.writer_under_inspiration
- end
+end
- c = Print_Edition.new(Book.new)
- c.periodicity
- end
- end
-end
-
Index: lib/topics/object_model.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/topics/object_model.rb (date 1497217375000)
+++ lib/topics/object_model.rb (revision )
@@ -2,5 +2,24 @@

# exercise object model
module ObjectModel
+ module Linux_Friendly
+ def fork_process
+ super
+ end
+
+ end
+
+ class Desktop
+ def fork_process
+ "Parent: allocate memory"
+ end
+ def mine_bitcoins
+ inspect
+ end
+ end
+
+ class Laptop < Desktop
+ prepend Linux_Friendly
+ end
-
+
end
20 changes: 20 additions & 0 deletions lib/topics/object_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@

# exercise object model
module ObjectModel
module Linux_Friendly
def fork_process
super
end

end

class Desktop
def fork_process
"Parent: allocate memory"
end
def mine_bitcoins
inspect
end
end

class Laptop < Desktop
prepend Linux_Friendly
end

end
24 changes: 24 additions & 0 deletions lib/topics/state_and_behaviour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,28 @@

# exercise state and behaviour
module StateAndBehaviour

end
class Car
attr_accessor :year,:color,:model,:current_speed


def initialize (car_attributes)
@year=car_attributes[:year] || 2015
@color=car_attributes[:color] || 'purple'
@model=car_attributes[:model] || 'skyline'
@current_speed = car_attributes[:current_speed] = 8
end

def speed_up (speed_is_raising)
@current_speed+=speed_is_raising
end

def push_break (speed_decrease)
@current_speed-=speed_decrease
end

def self.default_car
Car.new(default_car)
end
end