class String

Extension methods for {String}

Public Instance Methods

dedent() click to toggle source
# File lib/nrser/core_ext/string.rb, line 42
def dedent
  NRSER.dedent self
end
ellipsis(*args) click to toggle source

Calls {NRSER.ellipsis} on `self`.

# File lib/nrser/core_ext/string.rb, line 76
def ellipsis *args
  NRSER.ellipsis self, *args
end
env_varize() click to toggle source

Attempt to convert `self` into an ENV var name.

@see NRSER::Sys::Env.varize

@return (see NRSER::Sys::Env.varize)

# File lib/nrser/core_ext/string.rb, line 175
def env_varize
  NRSER::Sys::Env.varize self
end
indent(*args) click to toggle source
# File lib/nrser/core_ext/string.rb, line 47
def indent *args
  NRSER.indent self, *args
end
squiggle() click to toggle source

The method I alias as unary `~`, with a full-name so I can find it and such, I guess.

It's a string formatter. Right now, it just calls {#squish}, but I would like to make it a bit smarter soon so it can be used on paragraph-structured text too.

It's meant to be used with the `%{}` string quote form, because that allows multi-line strings, but nothing stopping it from being used elsewhere too.

@example

~%{
  Hey there, here's some "stuff",
  and here's some MORE!
}
# => "Hey there, here's some \"stuff\", and here's some MORE!"

@return [String]

# File lib/nrser/core_ext/string.rb, line 30
def squiggle
  squish
end
Also aliased as: ~@
start_with?(*prefixes) click to toggle source

Augment {#start_with?} to accept {Regexp} prefixes.

I guess I always *just felt* like this should work… so now it does (kinda, at least).

Everything should work the exact same for {String} prefixes.

Use {Regexp} ones at your own pleasure and peril.

@param [String | Regexp] prefixes

Strings behave as usual per the standard lib.

Regexp sources are used to create a new Regexp with `\A` at the start -
unless their source already starts with `\A` or `^` - and those Regexp
are tested against the string.

Regexp options are also copied over if a new Regexp is created. I can
def imagine things getting weird with some exotic regular expression
or another, but this feature is really indented for very simple patterns,
for which it should suffice.

@return [Boolean]

`true` if `self` starts with *any* of the `prefixes`.
# File lib/nrser/core_ext/string.rb, line 117
def start_with? *prefixes
  unless prefixes.any? { |x| Regexp === x }
    return stdlib_start_with? *prefixes
  end

  prefixes.any? { |prefix|
    case prefix
    when Regexp
      unless prefix.source.start_with? '\A', '^'
        prefix = Regexp.new( "\\A#{ prefix.source }", prefix.options )
      end
      
      prefix =~ self
    else
      stdlib_start_with? prefix
    end
  }
end
Also aliased as: stdlib_start_with?
stdlib_start_with?(*prefixes)

Alias the stdlib {#start_with?} 'cause we'll need to use it when redefining the method below.

Alias for: start_with?
to_const() click to toggle source
# File lib/nrser/core_ext/string.rb, line 52
def to_const
  safe_constantize
end
to_const!() click to toggle source
# File lib/nrser/core_ext/string.rb, line 57
def to_const!
  constantize
end
to_pn() click to toggle source

@return [Pathname]

Convert self into a {Pathname}
# File lib/nrser/core_ext/string.rb, line 65
def to_pn
  Pathname.new self
end
u_bold() click to toggle source

Calls {NRSER.u_bold} on `self`

# File lib/nrser/core_ext/string.rb, line 147
def u_bold
  NRSER.u_bold self
end
u_bold_italic() click to toggle source

Calls {NRSER.u_bold_italic} on `self`

# File lib/nrser/core_ext/string.rb, line 153
def u_bold_italic
  NRSER.u_bold_italic self
end
u_italic() click to toggle source

Calls {NRSER.u_italic} on `self`

# File lib/nrser/core_ext/string.rb, line 141
def u_italic
  NRSER.u_italic self
end
u_mono() click to toggle source

Calls {NRSER.u_mono} on `self`

# File lib/nrser/core_ext/string.rb, line 159
def u_mono
  NRSER.u_mono self
end
unblock() click to toggle source
# File lib/nrser/core_ext/string.rb, line 37
def unblock
  NRSER.unblock self
end
whitespace?() click to toggle source
# File lib/nrser/core_ext/string.rb, line 70
def whitespace?
  NRSER.whitespace? self
end
words(*args, &block) click to toggle source

Calls {NRSER.words} on `self`

# File lib/nrser/core_ext/string.rb, line 82
def words *args, &block
  NRSER::words self, *args, &block
end
~@()
Alias for: squiggle