Posts with #RubyTips

#RubyTips

Public posts on X that use #RubyTips.

Related hashtags

  1. Prathamesh Sonpatki✓@prathamesh2_
    #RubyTips String class provides handy methods `start_with?` and `end_with?` which basically do what they say. As argument they can take multiple strings and return true if any one of them matches with start or end of the string respectively. #Ruby
    Download
    0524
  2. Jesus Castello@matugm
    Ruby Tip: You can convert an array into a hash using the Hash#[] method. Example: Hash[Array('a'..'z').zip(Array('a'..'z').rotate)] #ruby #rubyguides #rubytips
    2712
  3. Jesus Castello@matugm
    [Ruby Tip] You can set the default value of a hash after creating it (either with {}, or to_h) Like this: h = {} h.default = 0 You can also set the default proc like this: h.default_proc = ->(h, k) { 123 } #ruby #rubyguides #rubytips
    015
  4. Jesus Castello@matugm
    Ruby Tip: You can use Regexp.last_match instead of the ugly $~ variable to get access to the results of your last regex. /c(.)t/ =~ 'cat' Regexp.last_match(0) # "cat" Regexp.last_match(1) # "a" #Ruby #RubyGuides #RubyTips
    002
  5. Jesus Castello@matugm
    Ruby Tip: Since Ruby 2.4 you can use the String#match? method to find out if a regular expression matches a string. This method returns true / false & it will not update $~ and related variables. This translates into more performance (3x) :) #ruby #rubytips #rubyguides
    144
  6. Show more posts