Class: Rubysh::FD

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysh/fd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fileno) ⇒ FD

Returns a new instance of FD.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubysh/fd.rb', line 5

def initialize(fileno)
  case fileno
  when Integer
    # pass
  when :stdin
    fileno = 0
  when :stdout
    fileno = 1
  when :stderr
    fileno = 2
  else
    raise Rubysh::Error::BaseError.new("Fileno must be an integer or one of :stdin, :stdout, :stderr, not #{fileno.inspect}")
  end

  @fileno = fileno
end

Instance Attribute Details

#filenoObject

Returns the value of attribute fileno.



3
4
5
# File 'lib/rubysh/fd.rb', line 3

def fileno
  @fileno
end

Instance Method Details

#<(target) ⇒ Object



26
27
28
# File 'lib/rubysh/fd.rb', line 26

def <(target)
  Redirect.new(self, '<', target)
end

#<<Object



30
31
32
# File 'lib/rubysh/fd.rb', line 30

def <<
  Rubysh.<<(self)
end

#==(other) ⇒ Object



42
43
44
45
# File 'lib/rubysh/fd.rb', line 42

def ==(other)
  self.class == other.class &&
    self.fileno == other.fileno
end

#>(target) ⇒ Object



22
23
24
# File 'lib/rubysh/fd.rb', line 22

def >(target)
  Redirect.new(self, '>', target)
end

#inspectObject



34
35
36
# File 'lib/rubysh/fd.rb', line 34

def inspect
  to_s
end

#to_sObject



38
39
40
# File 'lib/rubysh/fd.rb', line 38

def to_s
  "FD: #{@fileno}"
end