Class: HighLine::Simulate

### Home Classes Methods

### In Files

- lib/highline/simulate.rb

### Parent

Object

### Methods

- ::new
- ::with
- #eof?
- #getbyte
- #gets

### Files

- INSTALL
- LICENSE
- README.rdoc
- TODO

### Class/Module Index

Quicksearch

- HighLine
- HighLine::ColorScheme
- HighLine::HighLine
- HighLine::HighLine::HighLine
- HighLine::HighLine::HighLine::String
- HighLine::Menu
- HighLine::Question
- HighLine::Question::NoAutoCompleteMatch
- HighLine::QuestionError
- HighLine::SampleColorScheme
- HighLine::Simulate
- HighLine::StringExtensions
- HighLine::Style
- HighLine::SystemExtensions
- HighLine::SystemExtensions::WinAPI
- IO
- Kernel
- Object
- String
- StringIO

No matching classes.

# HighLine::Simulate

Simulates Highline input for use in tests.

### Public Class Methods

new(strings) click to toggle source

Creates a simulator with an array of Strings as a script

    # File lib/highline/simulate.rb, line 15
    def initialize(strings)
      @strings = strings
    end

with(*strings) click to toggle source

A wrapper method that temporarily replaces the Highline instance in $terminal with an instance of this object for the duration of the block

    # File lib/highline/simulate.rb, line 40
    def self.with(*strings)
      @input = $terminal.instance_variable_get :@input
      $terminal.instance_variable_set :@input, new(strings)
      yield
    ensure
      $terminal.instance_variable_set :@input, @input
    end

### Public Instance Methods

eof?() click to toggle source

The simulator handles its own EOF

    # File lib/highline/simulate.rb, line 35
    def eof?
      false
    end

getbyte() click to toggle source

Simulate StringIO#getbyte by shifting a single character off of the next line of the script

    # File lib/highline/simulate.rb, line 25
    def getbyte
      line = gets
      if line.length > 0
        char = line.slice! 0
        @strings.unshift line
        char
      end
    end

gets() click to toggle source

Simulate StringIO#gets by shifting a string off of the script

    # File lib/highline/simulate.rb, line 20
    def gets
      @strings.shift
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.