Tag: ruby

ruby strftime options

Every time I need to format ruby’s strftime options, I need to search for it on the internet. Putting them down here so that I don’t have to do that again!

Date Formatting 1

%YYear with century (e.g. 2015, 1995, etc)
%mMonth of the year, zero-padded (01..12)
%BThe full month name (e.g. January)
%bThe abbreviated month name (e.g. Jan)
%dDay of the month, zero-padded (01..31)
%jDay of the year (001..366)

Flags

Don’t pad a numerical output
_Use spaced for padding
0Use zeros for padding
^Upcase the result string
#Change case
:Use colons for %z
Continue reading

ruby – update default bundler

Whenever I get this error, I have to again do a google search. So, this post is for me not to do that again!

Could not find 'bundler' (2.1.4) required by your .Gemfile.lock.
 (Gem::GemNotFoundException)
To update to the latest version installed on your system,
run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`

Unfortunately, the suggestions don’t quite work.

The correct way to fix this is to run these three commands:

gem install --default bundler
gem update --system
bundler update --bundler

Courtesy of StackOverflow. (The correct answer on StackOverflow didn’t quite work either!)

ruby Open3 module

What a fantastic module!

Every once in a while I get to know a bit more of Ruby and I feel the joy which Matz talks about!

From: The Philosophy of Ruby

For me the purpose of life is partly to have joy. Programmers often feel joy when they can concentrate on the creative side of programming, So Ruby is designed to make programmers happy.

Today I was looking for executing a program from within Ruby. Now this program takes command line input and gives some output as well. So, I went around trying the usual %x(program.rb) but obviously that didn’t work.

Finally I came across Open3 which is a core module of Ruby!

Continue reading

ruby Classes and Modules

Classes and Modules in ruby have always intrigued me!

So, I thought I’ll write some code to understand what they were.

Besides the standard Class aspects of ruby, there are a lot of interesting things that can be done with them – like singleton objects.

Modules, of course, give another level of flexibility.

Continue reading

ruby – ‘rvm not found’ when running cron or ssh command

rvm or the Ruby Version Manager, works perfectly fine when there is a single version of Ruby to be run on the system (among multiple versions installed, of course) around the entire system. In a production scenario, updating ruby itself is a task which is not taken lightly!

This worked perfectly until I encountered two quite different situations –

One scenario was where I wanted to execute a command via ssh into the server. So something like –

ssh user1@server1 'ruby ~/program.rb'

The other being when I wanted to run a ruby program via cron

In both these cases, I kept getting the error rvm not found. Initially, I couldn’t understand this at all, because every time I logged in and ran the program or the command it would run prefectly.

And then I learnt about the difference between a login and a non-login shell.

Continue reading

Copyright © 2024 the möbius trip

Theme by Anders NorenUp ↑