Class: XMP::StringInputMethod

Inherits:
IRB::InputMethod show all
Defined in:
lib/irb/xmp.rb

Instance Attribute Summary collapse

Attributes inherited from IRB::InputMethod

#file_name, #prompt

Instance Method Summary collapse

Methods inherited from IRB::InputMethod

#readable_atfer_eof?

Constructor Details

#initializeStringInputMethod

Returns a new instance of StringInputMethod.



55
56
57
58
# File 'lib/irb/xmp.rb', line 55

def initialize
  super
  @exps = []
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding



88
89
90
# File 'lib/irb/xmp.rb', line 88

def encoding
  @encoding
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/irb/xmp.rb', line 60

def eof?
  @exps.empty?
end

#getsObject



64
65
66
67
68
69
70
71
72
# File 'lib/irb/xmp.rb', line 64

def gets
  while l = @exps.shift
	next if /^\s+$/ =~ l
	l.concat "\n"
	print @prompt, l
	break
  end
  l
end

#puts(exps) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/irb/xmp.rb', line 74

def puts(exps)
  if @encoding and exps.encoding != @encoding
	enc = Encoding.compatible?(@exps.join("\n"), exps)
	if enc.nil?
	  raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
	else
	  @encoding = enc
	end
  else
	@encoding = exps.encoding
  end
  @exps.concat exps.split(/\n/)
end