Overview In Ruby, a regular expression is defined between two forward slashes. This is a way to differentiate a regular expression from a normal string. This is how a regex will be…
Tag: ruby
JSON parse a file or string in Ruby Language
Overview json module of ruby can be used a JSON parse a file or string in ruby language https://ruby-doc.org/stdlib-2.6.3/libdoc/json/rdoc/JSON.html It provides a parse function that can be used to parse a file….
Run Ruby language code in command line or terminal – Single-line and Multiline
Overview It is possible to run a ruby code directly on a command line or the terminal itself. We need to pass the -e flag. This is the syntax for the same…
Get full hostname and port from a URL in Ruby Language
Overview URI module of ruby can be used to get all parts from a URL. This module can be used to parse a URL and extract all parts https://ruby-doc.org/stdlib-2.5.1/libdoc/uri/rdoc/URI.html Once the given…
Convert Query Param String to Query Param Hash in Ruby Language
Overview Assume we have below query param string We want the output as Program Below is the program for the same Output
Extract a URL from a string in Ruby Language
Overview URI module can be used to extract URL from a given string https://ruby-doc.org/stdlib-2.5.1/libdoc/uri/rdoc/URI.html We can use the Extract method of the URI module https://ruby-doc.org/stdlib-2.5.1/libdoc/uri/rdoc/URI.html#method-c-extract Below is the signature of the method…
Parse a URL and extract all the parts in Ruby Language
Overview URI module can be used to parse a URL and extract all parts https://ruby-doc.org/stdlib-2.5.1/libdoc/uri/rdoc/URI.html Once the given URL is parsed correctly, then it will return the URI object. We can then…