Shopify Liquid for loop« an older post
a newer one »View enums in postgres

Ruby Notes

Snippet

Yeah, those small details I need to keep looking up as I switch among ruby, javascript, php, and python on any given day.

See also:
https://www.techotopia.com/index.php/Ruby_String_Replacement,_Substitution_and_Insertion
https://www.rubyguides.com/2019/07/ruby-gsub-method/

CSV notes at https://ruby-doc.org/stdlib-2.6.3/libdoc/csv/rdoc/CSV.html

# remove only leading and trailing whitespace (like PHP's trim) 
str.strip
 
# use a regular expression ( this evaluates to 
str = "white chocolate"
str.gsub("white", "dark")
 
# which are groupings, btw (this evaluates to "1a")
"a1".gsub(/(\w)(\d)/, '\2\1')
 
# puts and print
print "use a return at the end\n"
puts "automatically adds the newline"

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.