p = Person.new p.first_name = ‘Tian’ p.last_name = nil p.first_name? # => true p.last_name? # => false
from http://tech.natemurray.com/2007/03/ruby-shell-commands.html
Often times we want to interact with the operating system or run shell commands from within Ruby. Ruby provides a number of ways for us to perform this task.
Exec
Kernel#exec (or simply exec) replaces the current process by running the given command For example:
$ irb >> exec ‘echo “hello $HOSTNAME”‘ hello nate.local $
Notice [...]
from http://benwoodall.com/2011/06/rails-global-access-to-rake-dsl-methods-is-deprecated/
So apparently the newest version of Rake (0.9+) breaks rails. You will get the error: WARNING: Global access to Rake DSL methods is deprecated. Please Include … Rake::DSL into classes and modules which use the Rake DSL methods. The quick fix is to downgrade to Rake 0.8.7, but you can also add this little [...]
Name Aliases Description $! $ERROR_INFO The exception information message set by the last ‘raise’ (last exception thrown). $@ $ERROR_POSITION Array of the backtrace of the last exception thrown. $& $MATCH The string matched by the last successful pattern match in this scope. $` $PREMATCH The string to the left of the last successful match. [...]
deploy a branch
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
deploy current commit
set :branch, $1 if `git rev-parse HEAD` =~ /(\S+)/
from http://tagaholic.me/2009/05/11/demystifying-irb-commands.html
Irb is one of the most commonly used standard ruby libraries, yet most don’t seem to know much about it. I’ve lost count of the number of blog posts that explain some irb “tricks” or “secret” config options. This is the first in a series that aims to make irb less magical and more [...]
from http://tagaholic.me/2009/05/29/exploring-how-to-configure-irb.html#eval_history
In my last post we discussed irb’s commands. This post goes further into irb’s innards, exploring all of its configuration options.
Gettin Ready
For starters, I refer you to the pickaxe which has an excellent section on configuring irb. Also, this post assumes ruby 1.8.6 and irb 0.9.5, though it should apply to 1.9ers. [...]
from http://rails3blog.com/2010/09/error-no-such-file-to-load-readline-loaderror/
I was getting this error trying to start the rails console: error: no such file to load — readline (LoadError). I’m using rvm, rails3, ruby 1.9.2, Ubuntu 10.04.
I tracked down redline in my ruby source ~/.rvm/src/ruby-1.9.2-p0/ext/readline and ran:
ruby extconf.rb
This let me know I was missing these two packages:
libncurses5-dev [...]
from: http://stackoverflow.com/questions/6786983/how-do-i-get-gem-install-to-work-on-os-x-lion-with-ruby-1-8-7-without-seg-fault
Error output:
/Users/[my user]/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/timeout.rb:60: [BUG] Segmentation fault ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.0.0]
Solution:
rvm remove 1.8.7 CC=/usr/bin/gcc-4.2 rvm install 1.8.7
If you don’t have gcc-4.2 with the latest XCode 4, then go to the following to install:
-
Articles
- May 2012
- April 2012
- March 2012
- February 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
-
Meta