class CodeString
CodeString
is string with an indicator of the manipulated language It permits to secure concantenation Code strings simplifies code displaying
Constants
- VERSION
Attributes
default_language[RW]
language[R]
Public Class Methods
new(text, language = nil)
click to toggle source
Calls superclass method
# File lib/code_string.rb, line 18 def initialize(text, language = nil) @language = language || @@default_language super(text) end
Public Instance Methods
+(text)
click to toggle source
Calls superclass method
# File lib/code_string.rb, line 23 def +(text) if text.is_a?(CodeString) if language == text.language super text else raise IncompatibleLanguage, "Language #{language} is not compatible with language: #{text.language}" end else super text end end
<<(text)
click to toggle source
Calls superclass method
# File lib/code_string.rb, line 35 def <<(text) if text.is_a?(CodeString) if language == text.language super text else raise IncompatibleLanguage, "Language #{language} is not compatible with language: #{text.language}" end else super text.to_s end end
dig(*args)
click to toggle source
# File lib/code_string.rb, line 63 def dig(*args) options = args.last.is_a?(Hash) ? args.delete_at(-1) : {} depth = args.shift || options[:depth] || 1 spacer = args.shift || options[:spacer] || ' ' (strip.gsub(/^/, spacer * depth) + "\n").c(@language) end
inspect()
click to toggle source
# File lib/code_string.rb, line 59 def inspect to_s end
to_formatted_s()
click to toggle source
# File lib/code_string.rb, line 47 def to_formatted_s string = '' index = 1 string << "# language: #{language}\n" string << "# encoding: #{encoding}\n" for line in split(/\n/) string << index.to_s.rjust(4) + ': ' + line + "\n" index += 1 end string end