{"id":18270405,"url":"https://github.com/zdavison/NSString-Ruby","last_synced_at":"2025-04-05T01:30:34.407Z","repository":{"id":7179286,"uuid":"8481353","full_name":"zdavison/NSString-Ruby","owner":"zdavison","description":"NSString category providing common Ruby String methods.","archived":false,"fork":false,"pushed_at":"2016-02-23T07:25:13.000Z","size":329,"stargazers_count":405,"open_issues_count":1,"forks_count":25,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-03-14T19:53:33.998Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zdavison.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-28T15:01:10.000Z","updated_at":"2024-01-16T17:39:55.000Z","dependencies_parsed_at":"2022-08-20T01:20:18.623Z","dependency_job_id":null,"html_url":"https://github.com/zdavison/NSString-Ruby","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdavison%2FNSString-Ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdavison%2FNSString-Ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdavison%2FNSString-Ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zdavison%2FNSString-Ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zdavison","download_url":"https://codeload.github.com/zdavison/NSString-Ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247146983,"owners_count":20891605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:38:35.964Z","updated_at":"2025-04-05T01:30:34.116Z","avatar_url":"https://github.com/zdavison.png","language":"Objective-C","readme":"NSString+Ruby [![Build Status](https://travis-ci.org/zdavison/NSString-Ruby.png?branch=master)](https://travis-ci.org/zdavison/NSString-Ruby)\n====================\n\nIntro\n---------------------\nNSString+Ruby is an attempt to improve NSString by porting Ruby String methods onto a category on NSString. \nThis means you can use the majority of Ruby String methods in obj-c, with the exception of a few unnecessary, and\nunimplimented (as of yet).\n\nNext Improvements\n---------------------\nEven better format/concat options  \nRuby style block execution\n\nDifferences / Important notes\n---------------------\nChanges have been made to method names, mostly to line up with traditional objective-c naming conventions, the rule\ngenerally being that all shorthand words have been extended to their full equivalent (eg: rStrip is rightStrip).\n\nOriginal methods provided by objective-c are not aliased to Ruby equivalents.\n\nBlocks are available for some methods, and not others, mostly for language paradigm reasons.\n\nOperator overloading has been mimicked to the best of our ability, using clever shorthand and unnamed methods,\nthe equivalent of the concatenation operator (+), would be (:) in NSString+Ruby, as follows:\n\n```ruby\n\"hello \" + \"world\"      #=\u003e\"hello world\"\n```\n\n```objective-c\n[@\"hello \":@\"world\",nil];   //\"hello world\"\n```\n\nThis is still a little ugly, but is the least amount of code you'd need to write in obj-c to do concatenation now.\n\nArray/index style accessors are provided through:\n\n```objective-c\n-(id)objectAtIndexedSubscript:(NSUInteger)index;\n-(id)objectForKeyedSubscript:(id)key;\n```\n\n...and provide for the majority of Ruby style functionality, the following Ruby methods, for example, are all implemented:\n\n```ruby\n(Ruby)\n a = \"hello there\"\n a[1]                   #=\u003e \"e\"\n a[2, 3]                #=\u003e \"llo\"\n a[-3, 2]               #=\u003e \"er\"\n a[2..3]                #=\u003e \"ll\"\n a[7..-2]               #=\u003e \"her\"\n a[-4..-2]              #=\u003e \"her\"\n a[-2..-4]              #=\u003e nil\n a[12..-1]              #=\u003e nil\n a[%r[aeiou](.){2}]     #=\u003e \"ell\"\n a[\"lo\"]                #=\u003e \"lo\"\n a[\"bye\"]               #=\u003e nil\n```\n\n```objective-c\nNSString *a = @\"hello there\";\na[1];                   // \"e\"\n[a:2:3];                // \"llo\"\n[a:-3:2];               // \"er\"\n```\n\nRanges are provided through C-string shorthand and nameless methods, allowing you to write the following:\n\n```objective-c\nNSString *a = @\"hello there\";\n[a:2:\"..\":3];            // \"ll\"\n[a:7:\"..\":-2];           // \"her\"\n[a:-4:\"..\":-2]           // \"her\"\n[a:-2:\"..\":-4]           // nil\n[a:12:\"..\":-1]           // nil\n```\n\nRegex matching also works, and is provided as the primary means of matching, almost anything that takes a string\ncan take a regex pattern.\n\n```objective-c\nNSString *a = @\"hello there\";\na[@\"[aeiou](.){2}\"]     // ell\na[\"lo\"]                 // lo\na[\"bye\"]                // nil\n```\n\niOS Requirements / ARC Status\n---------------------\nNSString+Ruby requires iOS 5.0+, and is ARC enabled.\n\nInstallation\n---------------------\nInstallation can be done using [CocoaPods](http://cocoapods.org):\nadd `pod 'NSString+Ruby'` to your `Podfile`, then run `pod install`.\n\nTests\n---------------------\nTests are provided through Kiwi ( https://github.com/allending/Kiwi ), and are largely reproduced from the Ruby String\nReference page ( http://www.ruby-doc.org/core-1.9.3/String.html ), some methods may be changed slightly\nin how they function, but for the most part the goal is to ape Ruby behaviour.\n\nNSMutableString\n---------------------\nNSMutableString has mutating versions of all the usual destructive methods. The modifier `InPlace` \nis used to signify a mutating/destructive method, vs the Ruby `!` bang modifier.\n\n\n\n\n\n# Method List\n\nHere is a full equivalence list of methods provided (Notes are provided in brackets for when things are purposefully\nnot implemented, blank lines will be implemented in future versions).\n\nPlease consult the Ruby String Reference page ( http://www.ruby-doc.org/core-1.9.3/String.html ) for method behaviour\ndocumentation.\n\n## NSString\n```\n ::try_convert\n #%               (no sensible way to implement this)\n #*             x:\n #+             :\n #\u003c\u003c            :\n #\u003c=\u003e           compare:\n #==            isEqualToString:\n #===           ==\n #=~            index:\n #[]            start:shorthand:end |\u003e [@\"string\" :1:@\"..\":3]\n                @\"string\"[1]\n                @\"string\"{@\"regex\"}\n                @\"string\"{@[1,3]}\n #[]=             (no mutating methods)\n #ascii_only?   isASCII:\n #bytes         bytes:\n #bytesize        \n #byteslice\n #capitalize    capitalizedString\n #casecmp       caseInsensitiveCompare:\n #center        center: \n                center:with:\n #chars         chars:\n #chomp         chomp\n                chomp:\n #chop          chop\n #chr           chr\n #clear           (unnecessary in obj-c)\n #codepoints    codePoints:\n #concat        concat:\n #count         count:\n #crypt           (unsure as of yet of which method to use for this, wary of providing easily misused insecure method)\n #delete        delete:\n #downcase      lowercaseString\n #dump            (implementation very close to |inspect|, |inspect| might suffice?)\n #each_byte     bytes:\n #each_char     chars:\n #each_codepointcodepoints:\n #each_line     lines:\n #empty?        isEmpty\n #encode        \n #encoding\n #end_with?     endsWith:\n #eql?          isEqualToString:\n #force_encoding\n #getbyte\n #gsub          substituteAll:\n                substituteAll:pattern\n #hash          hash\n #hex           hex\n #include?      includes:\n #index         match:\n                match:offset:\n #insert        insert:string:\n #inspect       inspect\n #intern          (not viable in obj-c, Ruby specific)\n #length        length\n #lines         lines:\n #ljust         leftJustify:\n                leftJustify:with:\n #lstrip        leftStrip\n #match         index:\n                index:offset:\n #next\n #oct           octal\n #ord           ordinal\n #partition     partition:\n #prepend       prepend:\n #replace         (unnecessary in obj-c)\n #reverse       reverse\n #rindex        lastIndex:\n                lastIndex:offset:\n #rjust         rightJustify:\n                rightJustify:with:\n #rpartition    rightPartition:\n #rstrip        rightStrip\n #scan          scan:\n #setbyte\n #size          length\n #slice         start:shorthand:end |\u003e [@\"string\" :1:@\"..\":3]\n                @\"string\"[1]\n                @\"string\"{@\"regex\"}\n                @\"string\"{@[1,3]}\n #split         split\n                split:\n                split:limit:\n #squeeze       squeeze\n                squeeze:\n #start_with?   startsWith:\n #strip         strip\n #sub           substituteFirst:\n                substituteLast:\n #succ\n #sum           sum\n                sum:\n #swapcase      swapcase\n #to_c\n #to_f          floatValue\n #to_i          intValue\n #to_r\n #to_s            (just use self)\n #to_str          (just use self)\n #to_sym          (not viable in obj-c, Ruby specific)\n #tr              (functionality is very similar to gsub for us, suggest using that instead)\n #tr_s\n #unpack\n #upcase        uppercaseString\n #upto\n #valid_encoding?\n \n```\n\n## NSMutableString\n```\n\n #capitalize!     capitalizeInPlace\n #chomp!          chompInPlace\n                  chompInPlace:\n #chop!           chopInPlace\n #delete!         deleteInPlace:\n #downcase!       lowercaseStringInPlace\n #gsub!           substituteAllInPlace:\n                  substituteAllInPlace:pattern\n #lstrip!         leftStripInPlace\n #reverse!        reverseInPlace\n #rstrip!         rightStripInPlace\n #squeeze!        squeezeInPlace\n                  squeezeInPlace:\n #strip!          stripInPlace\n #sub!            substituteFirstInPlace:\n                  substituteLastInPlace:\n #swapcase!       swapcaseInPlace\n #upcase!         uppercaseInPlace\n\n```\n","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdavison%2FNSString-Ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzdavison%2FNSString-Ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzdavison%2FNSString-Ruby/lists"}