Skip to content

Instantly share code, notes, and snippets.

@djwhitt
Created March 21, 2012 14:02
Show Gist options
  • Save djwhitt/2147112 to your computer and use it in GitHub Desktop.
Save djwhitt/2147112 to your computer and use it in GitHub Desktop.
# Magical Parslet change (hope it works)
class Parslet::Slice
attr_reader :size
def initialize(string, offset, line_cache=nil)
@str, @offset = string, offset
@line_cache = line_cache
@size = @str.size
end
def == other
to_str == other
end
def match(regexp)
to_str.match(regexp)
end
def +(other)
self.class.new(str << other.to_s, offset, line_cache)
end
def to_str
if @size != @str.size
@str.slice(0,@size)
else
@str
end
end
alias to_s to_str
def to_sym
to_str.to_sym
end
def to_int
Integer(to_str)
end
def to_i
to_str.to_i
end
def to_f
to_str.to_f
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment