Class: Code::Object::String
- Inherits:
-
Code::Object
- Object
- Code::Object
- Code::Object::String
- Defined in:
- lib/code/object/string.rb
Constant Summary collapse
- CLASS_DOCUMENTATION =
{ name: "String", description: "represents text and provides parsing, search, and transformation operations.", examples: ["\"hello\"", ":hello.upcase", "\"a,b\".split(\",\")"] }.freeze
- INSTANCE_FUNCTIONS =
{ "&" => { name: "&", description: "returns a function that calls the named selector.", examples: ["&\"to_string\"", "&\"upcase\"", "&\"value\""] }, "to_function" => { name: "to_function", description: "returns a function that calls the named selector.", examples: [ "\"to_string\".to_function", "\"upcase\".to_function", "\"value\".to_function" ] }, "*" => { name: "*", description: "returns the string repeated a number of times.", examples: ["\"a\" * 3", "\":\" * 2", "\"ab\" * 2"] }, "+" => { name: "+", description: "returns the string with another value appended.", examples: ["\"a\" + \"b\"", "\"count: \" + 1", "\":\" + :ok"] }, "downcase" => { name: "downcase", description: "returns the string converted to lowercase.", examples: [ "\"HELLO\".downcase", "\"Code\".downcase", "\"A1\".downcase" ] }, "lower_case" => { name: "lower_case", description: "returns the string converted to lowercase.", examples: [ "\"HELLO\".lower_case", "\"Code\".lower_case", "\"A1\".lower_case" ] }, "include?" => { name: "include?", description: "returns whether the string includes another string.", examples: [ "\"hello\".include?(\"ell\")", "\"hello\".include?(\"x\")", "\":name\".include?(\":\")" ] }, "member?" => { name: "member?", description: "returns whether the string includes another string.", examples: [ "\"hello\".member?(\"ell\")", "\"hello\".member?(\"x\")", "\":name\".member?(\":\")" ] }, "starts_with?" => { name: "starts_with?", description: "returns whether the string starts with another string.", examples: [ "\"hello\".starts_with?(\"he\")", "\"hello\".starts_with?(\"lo\")", "\":name\".starts_with?(\":\")" ] }, "start_with?" => { name: "start_with?", description: "returns whether the string starts with another string.", examples: [ "\"hello\".start_with?(\"he\")", "\"hello\".start_with?(\"lo\")", "\":name\".start_with?(\":\")" ] }, "ends_with?" => { name: "ends_with?", description: "returns whether the string ends with another string.", examples: [ "\"hello\".ends_with?(\"lo\")", "\"hello\".ends_with?(\"he\")", "\"file.rb\".ends_with?(\".rb\")" ] }, "end_with?" => { name: "end_with?", description: "returns whether the string ends with another string.", examples: [ "\"hello\".end_with?(\"lo\")", "\"hello\".end_with?(\"he\")", "\"file.rb\".end_with?(\".rb\")" ] }, "[]" => { name: "[]", description: "returns the character at an index.", examples: ["\"abc\"[0]", "\"abc\"[1]", "\"abc\"[2]"] }, "at" => { name: "at", description: "returns the character at an index.", examples: ["\"abc\".at(0)", "\"abc\".at(1)", "\"abc\".at(2)"] }, "get" => { name: "get", description: "returns the character at an index.", examples: ["\"abc\".get(0)", "\"abc\".get(1)", "\"abc\".get(2)"] }, "capitalize" => { name: "capitalize", description: "returns the string with its first character capitalized.", examples: [ "\"hello\".capitalize", "\"code\".capitalize", "\"already\".capitalize" ] }, "characters" => { name: "characters", description: "returns the string characters as a list.", examples: [ "\"abc\".characters", "\"hi\".characters", "\"\".characters" ] }, "bytes" => { name: "bytes", description: "returns the string bytes as a list.", examples: ["\"abc\".bytes", "\"A\".bytes", "\"\".bytes"] }, "bytesize" => { name: "bytesize", description: "returns the number of bytes in the string.", examples: ["\"abc\".bytesize", "\"A\".bytesize", "\"\".bytesize"] }, "byte_slice" => { name: "byte_slice", description: "returns a byte slice from the string.", examples: [ "\"abc\".byte_slice(0)", "\"abc\".byte_slice(0, 2)", "\"hello\".byte_slice(1, 3)" ] }, "codepoints" => { name: "codepoints", description: "returns the string codepoints as a list.", examples: [ "\"abc\".codepoints", "\"A\".codepoints", "\"\".codepoints" ] }, "character_code_at" => { name: "character_code_at", description: "returns the codepoint at an index.", examples: [ "\"abc\".character_code_at(0)", "\"abc\".character_code_at(1)", "\"abc\".character_code_at" ] }, "ordinal" => { name: "ordinal", description: "returns the codepoint for the first character.", examples: ["\"a\".ordinal", "\"A\".ordinal", "\"1\".ordinal"] }, "chomp" => { name: "chomp", description: "returns the string with a trailing record separator removed.", examples: ["\"a\\n\".chomp", "\"a\".chomp", "\"a\\r\\n\".chomp"] }, "chop" => { name: "chop", description: "returns the string with its last character removed.", examples: ["\"abc\".chop", "\"a\".chop", "\"\".chop"] }, "delete" => { name: "delete", description: "returns the string with matching characters removed.", examples: [ "\"hello\".delete(\"l\")", "\"123\".delete(\"2\")", "\"abc\".delete(\"z\")" ] }, "delete_prefix" => { name: "delete_prefix", description: "returns the string with a matching prefix removed.", examples: [ "\"hello\".delete_prefix(\"he\")", "\"hello\".delete_prefix(\"x\")", "\"file.rb\".delete_prefix(\"file\")" ] }, "delete_suffix" => { name: "delete_suffix", description: "returns the string with a matching suffix removed.", examples: [ "\"hello\".delete_suffix(\"lo\")", "\"hello\".delete_suffix(\"x\")", "\"file.rb\".delete_suffix(\".rb\")" ] }, "empty?" => { name: "empty?", description: "returns whether the string is empty.", examples: ["\"\".empty?", "\"a\".empty?", "\" \".empty?"] }, "clear" => { name: "clear", description: "empties the string and returns it.", examples: ["\"abc\".clear", "\"a\".clear", "\"\".clear"] }, "count" => { name: "count", description: "returns the count of matching characters.", examples: [ "\"hello\".count(\"l\")", "\"banana\".count(\"a\")", "\"abc\".count(\"z\")" ] }, "insert" => { name: "insert", description: "inserts a value at an index and returns the string.", examples: [ "\"ac\".insert(1, \"b\")", "\"bc\".insert(0, \"a\")", "\"ab\".insert(2, \"c\")" ] }, "prepend" => { name: "prepend", description: "prepends a value and returns the string.", examples: [ "\"b\".prepend(\"a\")", "\"world\".prepend(\"hello \")", "\"1\".prepend(0)" ] }, "concat" => { name: "concat", description: "appends values and returns the string.", examples: [ "\"a\".concat(\"b\")", "\"a\".concat(\"b\", \"c\")", "\"count\".concat(1)" ] }, "first" => { name: "first", description: "returns the first character or first characters.", examples: ["\"abc\".first", "\"abc\".first(2)", "\"\".first"] }, "index" => { name: "index", description: "returns the index of a matching substring.", examples: [ "\"hello\".index(\"l\")", "\"hello\".index(\"x\")", "\"banana\".index(\"na\")" ] }, "last" => { name: "last", description: "returns the last character or last characters.", examples: ["\"abc\".last", "\"ab\".last", "\"\".last"] }, "lines" => { name: "lines", description: "returns the string lines as a list.", examples: ["\"a\\nb\".lines", "\"a\".lines", "\"\".lines"] }, "reverse" => { name: "reverse", description: "returns the string with characters reversed.", examples: ["\"abc\".reverse", "\"ab\".reverse", "\"\".reverse"] }, "right_index" => { name: "right_index", description: "returns the last index of a matching substring.", examples: [ "\"hello\".right_index(\"l\")", "\"hello\".right_index(\"x\")", "\"banana\".right_index(\"na\")" ] }, "parameterize" => { name: "parameterize", description: "returns the string parameterized for identifiers or urls.", examples: [ "\"Hello world\".parameterize", "\"a b c\".parameterize", "\"Code Ruby\".parameterize" ] }, "squish" => { name: "squish", description: "returns the string with surrounding and repeated whitespace collapsed.", examples: [ "\" hello world \".squish", "\"a\\n b\".squish", "\"a b\".squish" ] }, "squeeze" => { name: "squeeze", description: "returns the string with repeated characters collapsed.", examples: [ "\"hellooo\".squeeze", "\"book\".squeeze(\"o\")", "\"aaab\".squeeze" ] }, "substitute" => { name: "substitute", description: "returns the string with the first match replaced.", examples: [ "\"hello\".substitute(\"l\", \"x\")", "\"abc\".substitute(\"a\", \"z\")", "\"abc\".substitute(\"x\", \"z\")" ] }, "substitute!" => { name: "substitute!", description: "replaces the first match in the string and returns it.", examples: [ "\"hello\".substitute!(\"l\", \"x\")", "\"abc\".substitute!(\"a\", \"z\")", "\"abc\".substitute!(\"x\", \"z\")" ] }, "substitute_all" => { name: "substitute_all", description: "returns the string with all matches replaced.", examples: [ "\"hello\".substitute_all(\"l\", \"x\")", "\"abcabc\".substitute_all(\"a\", \"z\")", "\"abc\".substitute_all(\"x\", \"z\")" ] }, "substitute_all!" => { name: "substitute_all!", description: "replaces all matches in the string and returns it.", examples: [ "\"hello\".substitute_all!(\"l\", \"x\")", "\"abcabc\".substitute_all!(\"a\", \"z\")", "\"abc\".substitute_all!(\"x\", \"z\")" ] }, "substitute_once" => { name: "substitute_once", description: "returns the string with the first match replaced.", examples: [ "\"hello\".substitute_once(\"l\", \"x\")", "\"abc\".substitute_once(\"a\", \"z\")", "\"abc\".substitute_once(\"x\", \"z\")" ] }, "substitute_once!" => { name: "substitute_once!", description: "replaces the first match in the string and returns it.", examples: [ "\"hello\".substitute_once!(\"l\", \"x\")", "\"abc\".substitute_once!(\"a\", \"z\")", "\"abc\".substitute_once!(\"x\", \"z\")" ] }, "swapcase" => { name: "swapcase", description: "returns the string with letter case swapped.", examples: [ "\"AbC\".swapcase", "\"hello\".swapcase", "\"ABC\".swapcase" ] }, "titleize" => { name: "titleize", description: "returns the string converted to title case.", examples: [ "\"hello world\".titleize", "\"code ruby\".titleize", "\"one\".titleize" ] }, "upcase" => { name: "upcase", description: "returns the string converted to uppercase.", examples: ["\"hello\".upcase", "\"Code\".upcase", "\"a1\".upcase"] }, "upper_case" => { name: "upper_case", description: "returns the string converted to uppercase.", examples: [ "\"hello\".upper_case", "\"Code\".upper_case", "\"a1\".upper_case" ] }, "size" => { name: "size", description: "returns the number of characters in the string.", examples: ["\"abc\".size", "\"\".size", "\"hello\".size"] }, "length" => { name: "length", description: "returns the number of characters in the string.", examples: ["\"abc\".length", "\"\".length", "\"hello\".length"] }, "strip" => { name: "strip", description: "returns the string with surrounding whitespace removed.", examples: ["\" a \".strip", "\"\\na\".strip", "\"a\".strip"] }, "left_strip" => { name: "left_strip", description: "returns the string with leading whitespace removed.", examples: [ "\" a\".left_strip", "\"\\na\".left_strip", "\"a\".left_strip" ] }, "right_strip" => { name: "right_strip", description: "returns the string with trailing whitespace removed.", examples: [ "\"a \".right_strip", "\"a\\n\".right_strip", "\"a\".right_strip" ] }, "slice" => { name: "slice", description: "returns a slice from the string.", examples: [ "\"abc\".slice(0)", "\"abc\".slice(0, 2)", "\"abc\".slice(1)" ] }, "left_justify" => { name: "left_justify", description: "returns the string left-justified to a width.", examples: [ "\"a\".left_justify(3)", "\"a\".left_justify(3, \".\")", "\"abc\".left_justify(2)" ] }, "right_justify" => { name: "right_justify", description: "returns the string right-justified to a width.", examples: [ "\"a\".right_justify(3)", "\"a\".right_justify(3, \".\")", "\"abc\".right_justify(2)" ] }, "center" => { name: "center", description: "returns the string centered within a width.", examples: [ "\"a\".center(3)", "\"a\".center(3, \".\")", "\"abc\".center(2)" ] }, "pad_start" => { name: "pad_start", description: "returns the string padded at the beginning.", examples: [ "\"a\".pad_start(3)", "\"a\".pad_start(3, \"0\")", "\"abc\".pad_start(2)" ] }, "pad_end" => { name: "pad_end", description: "returns the string padded at the end.", examples: [ "\"a\".pad_end(3)", "\"a\".pad_end(3, \"0\")", "\"abc\".pad_end(2)" ] }, "repeat" => { name: "repeat", description: "returns the string repeated a number of times.", examples: ["\"a\".repeat(3)", "\":\".repeat(2)", "\"ab\".repeat(2)"] }, "substring" => { name: "substring", description: "returns a substring from the string.", examples: [ "\"abc\".substring(0)", "\"abc\".substring(0, 2)", "\"hello\".substring(1, 3)" ] }, "split" => { name: "split", description: "returns the string split into a list.", examples: [ "\"a,b\".split(\",\")", "\"a b\".split", "\"a--b\".split(\"--\")" ] }, "words" => { name: "words", description: "returns the words in the string as a list.", examples: ["\"hello world\".words", "\"one two\".words", "\"\".words"] } }.freeze
Constants inherited from Code::Object
CLASS_FUNCTIONS, NUMBER_CLASSES
Constants included from Concerns::Shared
Concerns::Shared::COMPOUND_ASSIGNMENT_OPERATORS, Concerns::Shared::OPERATOR_METHOD_ALIASES, Concerns::Shared::SHARED_OPERATORS
Instance Attribute Summary
Attributes included from Concerns::Shared
Class Method Summary collapse
Instance Method Summary collapse
- #call(**args) ⇒ Object
- #code_byte_slice(index, length = nil) ⇒ Object
- #code_bytes ⇒ Object
- #code_bytesize ⇒ Object
- #code_capitalize ⇒ Object
- #code_center(width, padding = nil) ⇒ Object
- #code_character_code_at(index = nil) ⇒ Object
- #code_characters ⇒ Object
- #code_chomp ⇒ Object
- #code_chop ⇒ Object
- #code_clear ⇒ Object
- #code_codepoints ⇒ Object
- #code_concat(*values) ⇒ Object
- #code_count(*selectors) ⇒ Object
- #code_delete(value) ⇒ Object
- #code_delete_prefix(value) ⇒ Object
- #code_delete_suffix(value) ⇒ Object
- #code_downcase ⇒ Object
- #code_empty? ⇒ Boolean
- #code_end_with?(value) ⇒ Boolean
- #code_ends_with?(value) ⇒ Boolean
- #code_first(n = nil) ⇒ Object
- #code_get(value) ⇒ Object
- #code_include?(value) ⇒ Boolean
- #code_index(value) ⇒ Object
- #code_insert(index, value) ⇒ Object
- #code_inspect ⇒ Object
- #code_last(n = nil) ⇒ Object
- #code_left_justify(width, padding = nil) ⇒ Object
- #code_left_strip ⇒ Object
- #code_lines ⇒ Object
- #code_lower_case ⇒ Object
- #code_multiplication(other) ⇒ Object
- #code_ordinal ⇒ Object
- #code_pad_end(width, padding = nil) ⇒ Object
- #code_pad_start(width, padding = nil) ⇒ Object
- #code_parameterize ⇒ Object
- #code_plus(other) ⇒ Object
- #code_prepend(value) ⇒ Object
- #code_repeat(other) ⇒ Object
- #code_reverse ⇒ Object
- #code_right_index(value) ⇒ Object
- #code_right_justify(width, padding = nil) ⇒ Object
- #code_right_strip ⇒ Object
- #code_size ⇒ Object
- #code_slice(*arguments) ⇒ Object
- #code_split(value) ⇒ Object
- #code_squeeze(*selectors) ⇒ Object
- #code_squish ⇒ Object
- #code_start_with?(value) ⇒ Boolean
- #code_starts_with?(value) ⇒ Boolean
- #code_strip ⇒ Object
- #code_substitute(from = nil, to = nil) ⇒ Object
- #code_substitute!(from = nil, to = nil) ⇒ Object
- #code_substitute_all(from = nil, to = nil) ⇒ Object
- #code_substitute_all!(from = nil, to = nil) ⇒ Object
- #code_substitute_once(from = nil, to = nil) ⇒ Object
- #code_substitute_once!(from = nil, to = nil) ⇒ Object
- #code_substring(start = nil, finish = nil) ⇒ Object
- #code_swapcase ⇒ Object
- #code_titleize ⇒ Object
- #code_to_function(**_globals) ⇒ Object
- #code_upcase ⇒ Object
- #code_upper_case ⇒ Object
- #code_words ⇒ Object
-
#initialize(*args, **_kargs, &_block) ⇒ String
constructor
A new instance of String.
- #present? ⇒ Boolean
Methods inherited from Code::Object
class_documentation, class_functions, code_new, #code_new, documentation, documentation_for, documented_functions_for, function_documentation_for, function_documentation_registry_for, functions, inherited_function_documentation_for, instance_functions, maybe, #name, repeat, sorted_dictionary, |
Methods included from Concerns::Shared
#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_class_functions, #code_compare, #code_deep_duplicate, #code_different, #code_documentable_functions, #code_documentation, #code_duplicate, #code_dynamic_call, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_false?, #code_falsy?, code_fetch, #code_fetch, #code_functions, code_get, #code_greater, #code_greater_or_equal, #code_has_key?, #code_inclusive_range, #code_instance_functions, #code_instance_of?, #code_is_a?, #code_itself, #code_less, #code_less_or_equal, #code_name, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_respond_to?, #code_same_object?, #code_self, #code_send, code_set, #code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_tap, #code_then, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_true?, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ String
Returns a new instance of String.
546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/code/object/string.rb', line 546 def initialize(*args, **_kargs, &_block) self.raw = if args.first.is_an?(Class) args.first.raw.name elsif args.first.is_an?(Object) args.first.raw.to_s elsif args.first.is_a?(::Class) args.first.name elsif args.first args.first.to_s else "" end end |
Class Method Details
.function_documentation(scope) ⇒ Object
540 541 542 543 544 |
# File 'lib/code/object/string.rb', line 540 def self.function_documentation(scope) return INSTANCE_FUNCTIONS if scope == :instance {} end |
Instance Method Details
#call(**args) ⇒ Object
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 |
# File 'lib/code/object/string.rb', line 561 def call(**args) code_operator = args.fetch(:operator, nil).to_code code_arguments = args.fetch(:arguments, List.new).to_code globals = multi_fetch(args, *GLOBALS) code_value = code_arguments.code_first case code_operator.to_s when "&", "to_function" sig(args) code_to_function(**globals) when "*" sig(args) { Integer | Decimal } code_multiplication(code_value) when "+" sig(args) { Object } code_plus(code_value) when "downcase" sig(args) code_downcase when "lower_case" sig(args) code_lower_case when "include?", "member?" sig(args) { String } code_include?(code_value) when "starts_with?" sig(args) { String } code_starts_with?(code_value) when "start_with?" sig(args) { String } code_start_with?(code_value) when "ends_with?" sig(args) { String } code_ends_with?(code_value) when "end_with?" sig(args) { String } code_end_with?(code_value) when "[]", "at", "get" sig(args) { Integer } code_get(code_value) when "capitalize" sig(args) code_capitalize when "characters" sig(args) code_characters when "bytes" sig(args) code_bytes when "bytesize" sig(args) code_bytesize when "byte_slice" sig(args) { [Integer, Integer.maybe] } code_byte_slice(*code_arguments.raw) when "codepoints" sig(args) code_codepoints when "character_code_at" sig(args) { Integer.maybe } code_character_code_at(code_value) when "ordinal" sig(args) code_ordinal when "chomp" sig(args) code_chomp when "chop" sig(args) code_chop when "delete" sig(args) { String } code_delete(code_value) when "delete_prefix" sig(args) { String } code_delete_prefix(code_value) when "delete_suffix" sig(args) { String } code_delete_suffix(code_value) when "empty?" sig(args) code_empty? when "clear" sig(args) code_clear when "count" sig(args) { String.repeat(1) } code_count(*code_arguments.raw) when "insert" sig(args) { [Integer, Object] } code_insert(*code_arguments.raw) when "prepend" sig(args) { Object } code_prepend(code_value) when "concat" sig(args) { Object.repeat(1) } code_concat(*code_arguments.raw) when "first" sig(args) { Integer.maybe } code_first(code_value) when "index" sig(args) { String } code_index(code_value) when "last" sig(args) { Integer.maybe } code_last(code_value) when "lines" sig(args) code_lines when "reverse" sig(args) code_reverse when "right_index" sig(args) { String } code_right_index(code_value) when "parameterize" sig(args) code_parameterize when "squish" sig(args) code_squish when "squeeze" sig(args) { String.repeat } code_squeeze(*code_arguments.raw) when "substitute" sig(args) { [String, String.maybe] } code_substitute(*code_arguments.raw) when "substitute!" sig(args) { [String, String.maybe] } code_substitute!(*code_arguments.raw) when "substitute_all" sig(args) { [String, String.maybe] } code_substitute_all(*code_arguments.raw) when "substitute_all!" sig(args) { [String, String.maybe] } code_substitute_all!(*code_arguments.raw) when "substitute_once" sig(args) { [String, String.maybe] } code_substitute_once(*code_arguments.raw) when "substitute_once!" sig(args) { [String, String.maybe] } code_substitute_once!(*code_arguments.raw) when "swapcase" sig(args) code_swapcase when "titleize" sig(args) code_titleize when "upcase" sig(args) code_upcase when "upper_case" sig(args) code_upper_case when "size", "length" sig(args) code_size when "strip" sig(args) code_strip when "left_strip" sig(args) code_left_strip when "right_strip" sig(args) code_right_strip when "slice" sig(args) { Object.repeat(1) } code_slice(*code_arguments.raw) when "left_justify" sig(args) { [Integer, String.maybe] } code_left_justify(*code_arguments.raw) when "right_justify" sig(args) { [Integer, String.maybe] } code_right_justify(*code_arguments.raw) when "center" sig(args) { [Integer, String.maybe] } code_center(*code_arguments.raw) when "pad_start" sig(args) { [Integer, String.maybe] } code_pad_start(*code_arguments.raw) when "pad_end" sig(args) { [Integer, String.maybe] } code_pad_end(*code_arguments.raw) when "repeat" sig(args) { Integer | Decimal } code_repeat(code_value) when "substring" sig(args) { [Integer.maybe, Integer.maybe] } code_substring(*code_arguments.raw) when "split" sig(args) { String.maybe } code_split(code_value) when "words" sig(args) code_words else super end end |
#code_byte_slice(index, length = nil) ⇒ Object
794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/code/object/string.rb', line 794 def code_byte_slice(index, length = nil) code_index = index.to_code code_length = length.to_code value = if code_length.nothing? raw.byteslice(code_index.raw) else raw.byteslice(code_index.raw, code_length.raw) end value.to_code end |
#code_bytes ⇒ Object
786 787 788 |
# File 'lib/code/object/string.rb', line 786 def code_bytes List.new(raw.bytes) end |
#code_bytesize ⇒ Object
790 791 792 |
# File 'lib/code/object/string.rb', line 790 def code_bytesize Integer.new(raw.bytesize) end |
#code_capitalize ⇒ Object
778 779 780 |
# File 'lib/code/object/string.rb', line 778 def code_capitalize String.new(raw.capitalize) end |
#code_center(width, padding = nil) ⇒ Object
1090 1091 1092 1093 1094 1095 1096 |
# File 'lib/code/object/string.rb', line 1090 def code_center(width, padding = nil) code_width = width.to_code code_padding = padding.to_code code_padding = String.new(" ") if code_padding.nothing? String.new(raw.center(code_width.raw, code_padding.to_s)) end |
#code_character_code_at(index = nil) ⇒ Object
811 812 813 814 815 816 |
# File 'lib/code/object/string.rb', line 811 def code_character_code_at(index = nil) code_index = index.to_code code_index = Integer.new(0) if code_index.nothing? raw.codepoints[code_index.raw].to_code end |
#code_characters ⇒ Object
782 783 784 |
# File 'lib/code/object/string.rb', line 782 def code_characters List.new(raw.chars) end |
#code_chomp ⇒ Object
822 823 824 |
# File 'lib/code/object/string.rb', line 822 def code_chomp String.new(raw.chomp) end |
#code_chop ⇒ Object
826 827 828 |
# File 'lib/code/object/string.rb', line 826 def code_chop String.new(raw.chop) end |
#code_clear ⇒ Object
849 850 851 852 |
# File 'lib/code/object/string.rb', line 849 def code_clear raw.clear self end |
#code_codepoints ⇒ Object
807 808 809 |
# File 'lib/code/object/string.rb', line 807 def code_codepoints List.new(raw.codepoints) end |
#code_concat(*values) ⇒ Object
875 876 877 878 |
# File 'lib/code/object/string.rb', line 875 def code_concat(*values) values.each { |value| raw.concat(value.to_code.to_s) } self end |
#code_count(*selectors) ⇒ Object
854 855 856 857 858 |
# File 'lib/code/object/string.rb', line 854 def code_count(*selectors) code_selectors = selectors.to_code Integer.new(raw.count(*code_selectors.raw.map(&:to_s))) end |
#code_delete(value) ⇒ Object
830 831 832 833 |
# File 'lib/code/object/string.rb', line 830 def code_delete(value) code_value = value.to_code String.new(raw.delete(code_value.raw)) end |
#code_delete_prefix(value) ⇒ Object
835 836 837 838 |
# File 'lib/code/object/string.rb', line 835 def code_delete_prefix(value) code_value = value.to_code String.new(raw.delete_prefix(code_value.raw)) end |
#code_delete_suffix(value) ⇒ Object
840 841 842 843 |
# File 'lib/code/object/string.rb', line 840 def code_delete_suffix(value) code_value = value.to_code String.new(raw.delete_suffix(code_value.raw)) end |
#code_downcase ⇒ Object
762 763 764 |
# File 'lib/code/object/string.rb', line 762 def code_downcase String.new(raw.downcase) end |
#code_empty? ⇒ Boolean
845 846 847 |
# File 'lib/code/object/string.rb', line 845 def code_empty? Boolean.new(raw.empty?) end |
#code_end_with?(value) ⇒ Boolean
923 924 925 926 |
# File 'lib/code/object/string.rb', line 923 def code_end_with?(value) code_value = value.to_code Boolean.new(raw.end_with?(code_value.raw)) end |
#code_ends_with?(value) ⇒ Boolean
928 929 930 |
# File 'lib/code/object/string.rb', line 928 def code_ends_with?(value) code_end_with?(value) end |
#code_first(n = nil) ⇒ Object
1030 1031 1032 1033 1034 |
# File 'lib/code/object/string.rb', line 1030 def code_first(n = nil) code_n = n.to_code code_n = Integer.new(1) if code_n.nothing? String.new(raw.first(code_n.raw)) end |
#code_get(value) ⇒ Object
880 881 882 883 |
# File 'lib/code/object/string.rb', line 880 def code_get(value) code_value = value.to_code raw[code_value.raw].to_code end |
#code_include?(value) ⇒ Boolean
885 886 887 888 |
# File 'lib/code/object/string.rb', line 885 def code_include?(value) code_value = value.to_code Boolean.new(raw.include?(code_value.raw)) end |
#code_index(value) ⇒ Object
890 891 892 893 |
# File 'lib/code/object/string.rb', line 890 def code_index(value) code_value = value.to_code raw.index(code_value.raw).to_code end |
#code_insert(index, value) ⇒ Object
860 861 862 863 864 865 866 |
# File 'lib/code/object/string.rb', line 860 def code_insert(index, value) code_index = index.to_code code_value = value.to_code raw.insert(code_index.raw, code_value.to_s) self end |
#code_inspect ⇒ Object
972 973 974 |
# File 'lib/code/object/string.rb', line 972 def code_inspect String.new(raw.inspect) end |
#code_last(n = nil) ⇒ Object
895 896 897 898 899 |
# File 'lib/code/object/string.rb', line 895 def code_last(n = nil) code_n = n.to_code code_n = Integer.new(1) if code_n.nothing? String.new(raw.last(code_n.raw)) end |
#code_left_justify(width, padding = nil) ⇒ Object
1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/code/object/string.rb', line 1074 def code_left_justify(width, padding = nil) code_width = width.to_code code_padding = padding.to_code code_padding = String.new(" ") if code_padding.nothing? String.new(raw.ljust(code_width.raw, code_padding.to_s)) end |
#code_left_strip ⇒ Object
1048 1049 1050 |
# File 'lib/code/object/string.rb', line 1048 def code_left_strip String.new(raw.lstrip) end |
#code_lines ⇒ Object
901 902 903 |
# File 'lib/code/object/string.rb', line 901 def code_lines List.new(raw.lines) end |
#code_lower_case ⇒ Object
766 767 768 |
# File 'lib/code/object/string.rb', line 766 def code_lower_case code_downcase end |
#code_multiplication(other) ⇒ Object
905 906 907 908 |
# File 'lib/code/object/string.rb', line 905 def code_multiplication(other) code_other = other.to_code String.new(raw * code_other.raw) end |
#code_ordinal ⇒ Object
818 819 820 |
# File 'lib/code/object/string.rb', line 818 def code_ordinal raw.empty? ? Nothing.new : Integer.new(raw.ord) end |
#code_pad_end(width, padding = nil) ⇒ Object
1106 1107 1108 1109 1110 1111 1112 |
# File 'lib/code/object/string.rb', line 1106 def code_pad_end(width, padding = nil) code_width = width.to_code code_padding = padding.to_code code_padding = String.new(" ") if code_padding.nothing? String.new(raw.ljust(code_width.raw, code_padding.to_s)) end |
#code_pad_start(width, padding = nil) ⇒ Object
1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/code/object/string.rb', line 1098 def code_pad_start(width, padding = nil) code_width = width.to_code code_padding = padding.to_code code_padding = String.new(" ") if code_padding.nothing? String.new(raw.rjust(code_width.raw, code_padding.to_s)) end |
#code_parameterize ⇒ Object
976 977 978 |
# File 'lib/code/object/string.rb', line 976 def code_parameterize String.new(raw.parameterize) end |
#code_plus(other) ⇒ Object
932 933 934 935 |
# File 'lib/code/object/string.rb', line 932 def code_plus(other) code_other = other.to_code String.new(raw + code_other.to_s) end |
#code_prepend(value) ⇒ Object
868 869 870 871 872 873 |
# File 'lib/code/object/string.rb', line 868 def code_prepend(value) code_value = value.to_code raw.prepend(code_value.to_s) self end |
#code_repeat(other) ⇒ Object
910 911 912 |
# File 'lib/code/object/string.rb', line 910 def code_repeat(other) code_multiplication(other) end |
#code_reverse ⇒ Object
937 938 939 |
# File 'lib/code/object/string.rb', line 937 def code_reverse String.new(raw.reverse) end |
#code_right_index(value) ⇒ Object
941 942 943 944 |
# File 'lib/code/object/string.rb', line 941 def code_right_index(value) code_value = value.to_code raw.rindex(code_value.raw).to_code end |
#code_right_justify(width, padding = nil) ⇒ Object
1082 1083 1084 1085 1086 1087 1088 |
# File 'lib/code/object/string.rb', line 1082 def code_right_justify(width, padding = nil) code_width = width.to_code code_padding = padding.to_code code_padding = String.new(" ") if code_padding.nothing? String.new(raw.rjust(code_width.raw, code_padding.to_s)) end |
#code_right_strip ⇒ Object
1052 1053 1054 |
# File 'lib/code/object/string.rb', line 1052 def code_right_strip String.new(raw.rstrip) end |
#code_size ⇒ Object
1036 1037 1038 |
# File 'lib/code/object/string.rb', line 1036 def code_size Integer.new(raw.size) end |
#code_slice(*arguments) ⇒ Object
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
# File 'lib/code/object/string.rb', line 1056 def code_slice(*arguments) code_arguments = arguments.to_code.raw if code_arguments.first.is_a?(Range) code_range = code_arguments.first range = ::Range.new( code_range.code_left.to_i, code_range.code_right.to_i, code_range.exclude_end? ) return raw.slice(range).to_code end raw.slice(*code_arguments.map(&:to_i)).to_code end |
#code_split(value) ⇒ Object
1127 1128 1129 1130 1131 1132 1133 1134 1135 |
# File 'lib/code/object/string.rb', line 1127 def code_split(value) code_value = value.to_code if code_value.nothing? List.new(raw.split) else List.new(raw.split(code_value.to_s)) end end |
#code_squeeze(*selectors) ⇒ Object
984 985 986 987 988 |
# File 'lib/code/object/string.rb', line 984 def code_squeeze(*selectors) code_selectors = selectors.to_code String.new(raw.squeeze(*code_selectors.raw.map(&:to_s))) end |
#code_squish ⇒ Object
980 981 982 |
# File 'lib/code/object/string.rb', line 980 def code_squish String.new(raw.squish) end |
#code_start_with?(value) ⇒ Boolean
919 920 921 |
# File 'lib/code/object/string.rb', line 919 def code_start_with?(value) code_starts_with?(value) end |
#code_starts_with?(value) ⇒ Boolean
914 915 916 917 |
# File 'lib/code/object/string.rb', line 914 def code_starts_with?(value) code_value = value.to_code Boolean.new(raw.start_with?(code_value.raw)) end |
#code_strip ⇒ Object
1040 1041 1042 1043 1044 1045 1046 |
# File 'lib/code/object/string.rb', line 1040 def code_strip String.new(raw.strip) rescue ArgumentError, Encoding::CompatibilityError => e raise unless e..include?("invalid byte sequence") String.new(sanitized_utf8_raw.strip) end |
#code_substitute(from = nil, to = nil) ⇒ Object
990 991 992 |
# File 'lib/code/object/string.rb', line 990 def code_substitute(from = nil, to = nil) code_substitute_all(from, to) end |
#code_substitute!(from = nil, to = nil) ⇒ Object
994 995 996 |
# File 'lib/code/object/string.rb', line 994 def code_substitute!(from = nil, to = nil) code_substitute_all!(from, to) end |
#code_substitute_all(from = nil, to = nil) ⇒ Object
998 999 1000 1001 1002 1003 |
# File 'lib/code/object/string.rb', line 998 def code_substitute_all(from = nil, to = nil) code_from = from.to_code code_to = to.to_code String.new(raw.gsub(code_from.to_s, code_to.to_s)) end |
#code_substitute_all!(from = nil, to = nil) ⇒ Object
1005 1006 1007 1008 |
# File 'lib/code/object/string.rb', line 1005 def code_substitute_all!(from = nil, to = nil) self.raw = code_substitute_all(from, to).raw self end |
#code_substitute_once(from = nil, to = nil) ⇒ Object
1010 1011 1012 1013 1014 1015 |
# File 'lib/code/object/string.rb', line 1010 def code_substitute_once(from = nil, to = nil) code_from = from.to_code code_to = to.to_code String.new(raw.sub(code_from.to_s, code_to.to_s)) end |
#code_substitute_once!(from = nil, to = nil) ⇒ Object
1017 1018 1019 1020 |
# File 'lib/code/object/string.rb', line 1017 def code_substitute_once!(from = nil, to = nil) self.raw = code_substitute_once(from, to).raw self end |
#code_substring(start = nil, finish = nil) ⇒ Object
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 |
# File 'lib/code/object/string.rb', line 1114 def code_substring(start = nil, finish = nil) code_start = start.to_code code_finish = finish.to_code start_index = code_start.nothing? ? 0 : code_start.raw finish_index = code_finish.nothing? ? raw.length : code_finish.raw start_index = 0 if start_index.negative? finish_index = 0 if finish_index.negative? start_index, finish_index = finish_index, start_index if start_index > finish_index String.new(raw[start_index...finish_index].to_s) end |
#code_swapcase ⇒ Object
1022 1023 1024 |
# File 'lib/code/object/string.rb', line 1022 def code_swapcase String.new(raw.swapcase) end |
#code_titleize ⇒ Object
1026 1027 1028 |
# File 'lib/code/object/string.rb', line 1026 def code_titleize String.new(raw.titleize) end |
#code_to_function(**_globals) ⇒ Object
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 |
# File 'lib/code/object/string.rb', line 946 def code_to_function(**_globals) unless /\A[A-Za-z_][A-Za-z0-9_]*[!?]?\z/.match?(raw) raise Error, "String#to_function: invalid function name" end Function.new( [{ name: "_" }], Node::Code.new( [ { left_operation: { first: { call: { name: "_" } }, others: [ { operator: ".", statement: { call: { name: raw } } } ] } } ] ) ) end |
#code_upcase ⇒ Object
770 771 772 |
# File 'lib/code/object/string.rb', line 770 def code_upcase String.new(raw.upcase) end |
#code_upper_case ⇒ Object
774 775 776 |
# File 'lib/code/object/string.rb', line 774 def code_upper_case code_upcase end |
#code_words ⇒ Object
1137 1138 1139 |
# File 'lib/code/object/string.rb', line 1137 def code_words List.new(raw.split) end |
#present? ⇒ Boolean
1141 1142 1143 |
# File 'lib/code/object/string.rb', line 1141 def present? raw.present? end |