Class: String
Overview
Extension methods for String
Unicode Stylization collapse
-
#u_bold ⇒ Object
Calls NRSER.u_bold on ‘self`.
-
#u_bold_italic ⇒ Object
Calls NRSER.u_bold_italic on ‘self`.
-
#u_italic ⇒ Object
Calls NRSER.u_italic on ‘self`.
-
#u_mono ⇒ Object
Calls NRSER.u_mono on ‘self`.
Inflection Instance Methods collapse
-
#env_varize ⇒ nil, String
Attempt to convert ‘self` into an ENV var name.
Instance Method Summary collapse
- #dedent ⇒ Object
-
#ellipsis(*args) ⇒ Object
Calls NRSER.ellipsis on ‘self`.
- #indent(*args) ⇒ Object
-
#squiggle ⇒ String
(also: #~@)
The method I alias as unary ‘~`, with a full-name so I can find it and such, I guess.
-
#start_with?(*prefixes) ⇒ Boolean
Augment #start_with? to accept Regexp prefixes.
-
#stdlib_start_with? ⇒ Object
Alias the stdlib #start_with? ‘cause we’ll need to use it when redefining the method below.
- #to_const ⇒ Object
- #to_const! ⇒ Object
-
#to_pn ⇒ Pathname
Convert self into a Pathname.
- #unblock ⇒ Object
- #whitespace? ⇒ Boolean
-
#words(*args, &block) ⇒ Object
Calls NRSER.words on ‘self`.
Instance Method Details
#dedent ⇒ Object
42 43 44 |
# File 'lib/nrser/core_ext/string.rb', line 42 def dedent NRSER.dedent self end |
#ellipsis(*args) ⇒ Object
Calls NRSER.ellipsis on ‘self`.
76 77 78 |
# File 'lib/nrser/core_ext/string.rb', line 76 def ellipsis *args NRSER.ellipsis self, *args end |
#env_varize ⇒ nil, String
Attempt to convert ‘self` into an ENV var name.
175 176 177 |
# File 'lib/nrser/core_ext/string.rb', line 175 def env_varize NRSER::Sys::Env.varize self end |
#indent(*args) ⇒ Object
47 48 49 |
# File 'lib/nrser/core_ext/string.rb', line 47 def indent *args NRSER.indent self, *args end |
#squiggle ⇒ String Also known as: ~@
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.
30 31 32 |
# File 'lib/nrser/core_ext/string.rb', line 30 def squiggle squish end |
#start_with?(*prefixes) ⇒ Boolean
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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# 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. ) end prefix =~ self else stdlib_start_with? prefix end } end |
#stdlib_start_with? ⇒ Object
Alias the stdlib #start_with? ‘cause we’ll need to use it when redefining the method below.
90 |
# File 'lib/nrser/core_ext/string.rb', line 90 alias_method :stdlib_start_with?, :start_with? |
#to_const ⇒ Object
52 53 54 |
# File 'lib/nrser/core_ext/string.rb', line 52 def to_const safe_constantize end |
#to_const! ⇒ Object
57 58 59 |
# File 'lib/nrser/core_ext/string.rb', line 57 def to_const! constantize end |
#to_pn ⇒ Pathname
Returns Convert self into a Pathname.
65 66 67 |
# File 'lib/nrser/core_ext/string.rb', line 65 def to_pn Pathname.new self end |
#u_bold ⇒ Object
Calls NRSER.u_bold on ‘self`
147 148 149 |
# File 'lib/nrser/core_ext/string.rb', line 147 def u_bold NRSER.u_bold self end |
#u_bold_italic ⇒ Object
Calls NRSER.u_bold_italic on ‘self`
153 154 155 |
# File 'lib/nrser/core_ext/string.rb', line 153 def u_bold_italic NRSER.u_bold_italic self end |
#u_italic ⇒ Object
Calls NRSER.u_italic on ‘self`
141 142 143 |
# File 'lib/nrser/core_ext/string.rb', line 141 def u_italic NRSER.u_italic self end |
#u_mono ⇒ Object
Calls NRSER.u_mono on ‘self`
159 160 161 |
# File 'lib/nrser/core_ext/string.rb', line 159 def u_mono NRSER.u_mono self end |
#unblock ⇒ Object
37 38 39 |
# File 'lib/nrser/core_ext/string.rb', line 37 def unblock NRSER.unblock self end |
#whitespace? ⇒ Boolean
70 71 72 |
# File 'lib/nrser/core_ext/string.rb', line 70 def whitespace? NRSER.whitespace? self end |
#words(*args, &block) ⇒ Object
Calls NRSER.words on ‘self`
82 83 84 |
# File 'lib/nrser/core_ext/string.rb', line 82 def words *args, &block NRSER::words self, *args, &block end |