Ruby: Uninitialized constant Redis Error

The problem occurred in a file titled redis.rb and having the following content: require 'redis' $redis = Redis.new(...) The gem was installed and still I was getting the same error. On search, I found this link. Solution Rename the file from redis.rb to redis-db.rb. It worked. Written with StackEdit.

Assertion failed: (!STR_EMBED_P(shared)), function str_new_frozen, file string.c, line 1075.

Solution If you workflow has Docker container, please stop the containers. Check with $docker ps and verify that all containers are in exited state.Set the right Ruby version. Find out from the project repo Makefile, build scripts. $ rbenv global 2.3.0 Update the bundler to same version as of Ruby. $ gem install bundler Reference…

A Clean Way to Run Multiple Versions of Python & Ruby

Solution Use pyenv and rbenv How It Works? These tools create a shim (or think of softlinks) for a version of the software. You can choose to run a version globally or locally in a shell. Switch to a version anytime you like. Run Python 3 & Python 2 without much trouble. Or no need…

Ruby Class Members: Getter & Setter

The simplest example of read_attr, write_attr in a class. class Person attr_reader :name, :age attr_writer :name, :age # creates the setter methods def initialize(name) [@name](http://twitter.com/name) = name end endmike = Person.new('Mike') mike.age = 20 # calling setter method mike.age # calling getter method, returns 20 Reference The example is verbatim from an easy to follow…

Understanding Ruby Symbols

Ruby is an interpreted language. It is dynamically typed and uses a new memory for a variable. A variable has a name and a value. Symbols are an optimized variable that holds single instance of memory. It is good for variables that assume the same values across the program such as hash table keys. h…

Adding Query Params to a URL in Ruby with HTTP

The clearest example was in a StackOverflow post require 'uri' def add_param(url, param_name, param_value) uri = URI(url) params = URI.decode_www_form(uri.query || "") << [param_name, param_value] uri.query = URI.encode_www_form(params) uri.to_s end You can pass a map of params key & values and get expected URL. Another example # prepare params. params = { 'id' => '12'…

%d bloggers like this: