When I try to move the Devise stuff into a module User::Devise and include it in class User, I got this warning ‘warning: toplevel constant Devise referenced by User::Devise’
Please see the code before and after for a solution.
Solution is to make User::Devise before you do the include for class User
Can’t find anything about casting an instance to specified class? Of cause, in Ruby, there is no such concept that you need to cast an instance in most of the cases. But how about you need to? Here is the answer:
By using ActiveRecord::Persistence.becomes, you can easily cast it to specified class.
For example:
from http://ar.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html :host - Defaults to “localhost”. :port - Defaults to 5432. :username - Defaults to nothing. :password - Defaults to nothing. :database - The name of the database. No default, must be provided. :schema_search_path - An optional schema search path for the connection given as a string of comma-separated schema names. This is backward-compatible with the :schema_order option. :encoding - An optional [...]
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 [...]
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. [...]
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 [...]
-
Articles
- 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