Class: MontyHallProblem::Doors
- Inherits:
-
Object
- Object
- MontyHallProblem::Doors
- Defined in:
- lib/monty_hall_problem.rb
Instance Attribute Summary collapse
-
#door ⇒ Object
Returns the value of attribute door.
-
#opened_door_idx ⇒ Object
Returns the value of attribute opened_door_idx.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #car_door_idx ⇒ Object
-
#initialize(size = 3) ⇒ Doors
constructor
A new instance of Doors.
- #no_car_door_idx ⇒ Object
- #put(door_idx) ⇒ Object
Constructor Details
#initialize(size = 3) ⇒ Doors
Returns a new instance of Doors.
51 52 53 54 55 |
# File 'lib/monty_hall_problem.rb', line 51 def initialize(size=3) self.size = size self.door = Array.new(size) { false } self.opened_door_idx = [] end |
Instance Attribute Details
#door ⇒ Object
Returns the value of attribute door.
48 49 50 |
# File 'lib/monty_hall_problem.rb', line 48 def door @door end |
#opened_door_idx ⇒ Object
Returns the value of attribute opened_door_idx.
49 50 51 |
# File 'lib/monty_hall_problem.rb', line 49 def opened_door_idx @opened_door_idx end |
#size ⇒ Object
Returns the value of attribute size.
47 48 49 |
# File 'lib/monty_hall_problem.rb', line 47 def size @size end |
Instance Method Details
#car_door_idx ⇒ Object
66 67 68 |
# File 'lib/monty_hall_problem.rb', line 66 def car_door_idx door.map.with_index{ |e, i| i if !!e }.compact end |
#no_car_door_idx ⇒ Object
70 71 72 |
# File 'lib/monty_hall_problem.rb', line 70 def no_car_door_idx door.map.with_index{ |e, i| i if !e }.compact end |
#put(door_idx) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/monty_hall_problem.rb', line 57 def put(door_idx) if door[door_idx] return false else door[door_idx] = true return true end end |