Module: Elixir::String
- Defined in:
- lib/elixir/string.rb
Class Method Summary collapse
- .at(string, index) ⇒ Object
- .capitalize(string) ⇒ Object
- .chunk(string, trait) ⇒ Object
- .codepoints(string) ⇒ Object
- .contains?(string, contents) ⇒ Boolean
- .downcase(string) ⇒ Object
- .duplicate(string, n) ⇒ Object
- .ends_with?(string, *suffixes) ⇒ Boolean
- .first(string) ⇒ Object
- .graphemes(string) ⇒ Object
- .last(string) ⇒ Object
- .length(string) ⇒ Object
- .ljust(string, length, padding = ' ') ⇒ Object
- .lstrip(string, char = :todo) ⇒ Object
- .match?(string, regex) ⇒ Boolean
- .next_codepoint(string) ⇒ Object
- .next_grapheme(string) ⇒ Object
- .printable?(string) ⇒ Boolean
- .replace(string, pattern, replacement, options = []) ⇒ Object
- .reverse(string) ⇒ Object
- .rjust(string, len, padding) ⇒ Object
- .rstrip(string, char = ' ') ⇒ Object
- .slice(string, range) ⇒ Object
- .split(string) ⇒ Object
- .split_at(string, offset) ⇒ Object
- .starts_with(string, prefix) ⇒ Object
- .strip(string, char = nil) ⇒ Object
- .to_atom(string) ⇒ Object
- .to_char_list(string) ⇒ Object
- .to_existing_atom(string) ⇒ Object
- .to_float(string) ⇒ Object
- .to_integer(string, base = 10) ⇒ Object
- .upcase(string) ⇒ Object
- .valid?(string) ⇒ Boolean
- .valid_character?(char) ⇒ Boolean
Class Method Details
.at(string, index) ⇒ Object
5 6 7 |
# File 'lib/elixir/string.rb', line 5 def at string, index string[index] end |
.capitalize(string) ⇒ Object
9 10 11 |
# File 'lib/elixir/string.rb', line 9 def capitalize string string.capitalize end |
.chunk(string, trait) ⇒ Object
13 14 15 |
# File 'lib/elixir/string.rb', line 13 def chunk string, trait # TODO end |
.codepoints(string) ⇒ Object
17 18 19 |
# File 'lib/elixir/string.rb', line 17 def codepoints string string.chars end |
.contains?(string, contents) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/elixir/string.rb', line 21 def contains? string, contents warn '[deprecation] Calling String.contains?/2 with an empty string is deprecated and will fail in the future' if contents.empty? string.include? contents end |
.downcase(string) ⇒ Object
27 28 29 |
# File 'lib/elixir/string.rb', line 27 def downcase string string.downcase end |
.duplicate(string, n) ⇒ Object
31 32 33 |
# File 'lib/elixir/string.rb', line 31 def duplicate string, n string * n end |
.ends_with?(string, *suffixes) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/elixir/string.rb', line 35 def ends_with? string, *suffixes warn '[deprecation] Calling String.ends_with?/2 with an empty string is deprecated and will fail in the future' if string.empty? string.end_with? *suffixes.flatten(1) end |
.first(string) ⇒ Object
41 42 43 |
# File 'lib/elixir/string.rb', line 41 def first string string[0] end |
.graphemes(string) ⇒ Object
45 46 47 |
# File 'lib/elixir/string.rb', line 45 def graphemes string string.chars end |
.last(string) ⇒ Object
49 50 51 |
# File 'lib/elixir/string.rb', line 49 def last string string[-1] end |
.length(string) ⇒ Object
53 54 55 |
# File 'lib/elixir/string.rb', line 53 def length string string.size end |
.ljust(string, length, padding = ' ') ⇒ Object
57 58 59 |
# File 'lib/elixir/string.rb', line 57 def ljust string, length, padding = ' ' string.ljust length, padding end |
.lstrip(string, char = :todo) ⇒ Object
61 62 63 |
# File 'lib/elixir/string.rb', line 61 def lstrip string, char = :todo string.lstrip end |
.match?(string, regex) ⇒ Boolean
65 66 67 |
# File 'lib/elixir/string.rb', line 65 def match? string, regex # TODO end |
.next_codepoint(string) ⇒ Object
69 70 71 |
# File 'lib/elixir/string.rb', line 69 def next_codepoint string [string[0], string[1..-1]] end |
.next_grapheme(string) ⇒ Object
73 74 75 |
# File 'lib/elixir/string.rb', line 73 def next_grapheme string [string[0], string[1..-1]] end |
.printable?(string) ⇒ Boolean
77 78 79 |
# File 'lib/elixir/string.rb', line 77 def printable? string # TODO end |
.replace(string, pattern, replacement, options = []) ⇒ Object
81 82 83 |
# File 'lib/elixir/string.rb', line 81 def replace string, pattern, replacement, = [] # TODO end |
.reverse(string) ⇒ Object
85 86 87 |
# File 'lib/elixir/string.rb', line 85 def reverse string string.reverse end |
.rjust(string, len, padding) ⇒ Object
89 90 91 |
# File 'lib/elixir/string.rb', line 89 def rjust string, len, padding # TODO end |
.rstrip(string, char = ' ') ⇒ Object
93 94 95 |
# File 'lib/elixir/string.rb', line 93 def rstrip string, char = ' ' # TODO end |
.slice(string, range) ⇒ Object
97 98 99 |
# File 'lib/elixir/string.rb', line 97 def slice string, range # TODO end |
.split(string) ⇒ Object
101 102 103 |
# File 'lib/elixir/string.rb', line 101 def split string string.split end |
.split_at(string, offset) ⇒ Object
105 106 107 |
# File 'lib/elixir/string.rb', line 105 def split_at string, offset # TODO end |
.starts_with(string, prefix) ⇒ Object
109 110 111 |
# File 'lib/elixir/string.rb', line 109 def starts_with string, prefix string.start_with? prefix end |
.strip(string, char = nil) ⇒ Object
113 114 115 |
# File 'lib/elixir/string.rb', line 113 def strip string, char = nil # TODO end |
.to_atom(string) ⇒ Object
117 118 119 |
# File 'lib/elixir/string.rb', line 117 def to_atom string string.to_sym end |
.to_char_list(string) ⇒ Object
121 122 123 |
# File 'lib/elixir/string.rb', line 121 def to_char_list string string.chars end |
.to_existing_atom(string) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/elixir/string.rb', line 125 def to_existing_atom string # Nothing to see here... >.> if Symbol.all_symbols.map(&:to_s).include? string string.to_sym else raise ArgumentError end end |
.to_float(string) ⇒ Object
134 135 136 |
# File 'lib/elixir/string.rb', line 134 def to_float string Float(string) end |
.to_integer(string, base = 10) ⇒ Object
138 139 140 |
# File 'lib/elixir/string.rb', line 138 def to_integer string, base = 10 Integer(string) end |
.upcase(string) ⇒ Object
142 143 144 |
# File 'lib/elixir/string.rb', line 142 def upcase string string.upcase end |
.valid?(string) ⇒ Boolean
146 147 148 |
# File 'lib/elixir/string.rb', line 146 def valid? string string.valid_encoding? end |
.valid_character?(char) ⇒ Boolean
150 151 152 |
# File 'lib/elixir/string.rb', line 150 def valid_character? char char.size == 1 && char.valid_encoding? end |