When was the last time you saw a real computer screen in a movie? Usually in movies we get some dumbed down looking operating system, or some totally unreal user interface, like flying through a 3D city to access a file. I’m sure even in the far off future, navigating a 3D virtual world will not be an efficient user interface for most computer systems.
So it was with great joy that I watched the latest Tron trailer. If you pause it at the moment Flynn’s son sits down at the computer terminal, you’ll see a real looking NIX operating system, as can be seen above. You’ll notice that both iostat and top can be seen running. The version name in the screen is “Solar OS 4.0.1” which as far as I know is a made up system, but is probably a play on SunOS and Solaris. Additionally, the platform name says “sun4m” which would make it a SPARC workstation, which would make sense if this is a 20 year old system.
nil?, empty? and blank?
rubyquicktips:
In Ruby, you check with nil? if an object is nil:
article = nil
article.nil? # => true
empty? checks if an element - like a string or an array f.e. - is empty:
# Array
[].empty? #=> true
# String
"".empty? #=> true
Rails adds the method blank? to the Object class:
An object is blank if it‘s false, empty, or a whitespace string. For example, “”, ” “, nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
Documentation: nil?, empty? (String, Array) and blank?
As of Rails 2.3, there’s also a handy new try() method on objects, which allows you to invoke a method on a possibly nil object without throwing a NoMethodError. This saves you the trouble of checking if your object is nil or not before accessing a method.
For example, previously you’d need to do something like
article = Article.find_by_title("My Article")
unless article.nil?
article.body
end
With try() you can skip the nil? check and do the following
Article.find_by_title("My Article").try(:body) => #body or nil