Class: Tryruby::Tutorial

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/tryruby/tutorial.rb

Overview

Base module for level DSL

Direct Known Subclasses

DefaultLevels

Defined Under Namespace

Modules: Commands

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTutorial

Returns a new instance of Tutorial.



12
13
14
15
16
17
18
19
# File 'lib/tryruby/tutorial.rb', line 12

def initialize
  @levels = []
  self.class.each do |block|
    builder = LevelBuilder.new
    builder.instance_eval(&block)
    @levels << builder.level
  end
end

Class Method Details

.each(&block) ⇒ Object



37
38
39
# File 'lib/tryruby/tutorial.rb', line 37

def self.each(&block)
  levels.each(&block)
end

.level(&block) ⇒ Object



41
42
43
# File 'lib/tryruby/tutorial.rb', line 41

def self.level(&block)
  levels << block
end

.levelsObject



45
46
47
# File 'lib/tryruby/tutorial.rb', line 45

def self.levels
  @levels ||= []
end

Instance Method Details

#[](i) ⇒ Object



21
22
23
# File 'lib/tryruby/tutorial.rb', line 21

def [](i)
  @levels[i]
end

#commandsObject



33
34
35
# File 'lib/tryruby/tutorial.rb', line 33

def commands
  self.class::Commands
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/tryruby/tutorial.rb', line 25

def each(&block)
  @levels.each(&block)
end

#lengthObject



29
30
31
# File 'lib/tryruby/tutorial.rb', line 29

def length
  @levels.length
end