Broken free weekly Rails (e)

1. Public protected private

With no arguments, sets the default visibility for subsequently defined methods to public . With arguments, sets the named methods to have public visibility.

Many things in Ruby is just method!

2. System

Executes cmd in a subshell, returning true if the command was found and ran successfully, false otherwise. An error status is available in $?. The arguments are processed in the same way as for Kernel:: exec.

system("echo *")
system("echo", "*")  # echo "*"


config.h main.rb


3. `

Returns the standard output of running cmd in a subshell. The built-in syntax% x (...) uses this method. Sets $? To the process status.

`date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"

`ls testdir`.split[1] #=> "main.rb"

`echo oops && exit 99` #=> "oops\n"

$?.exitstatus #=> 99

4. Reload

Reloads the attributes of this object from the database. The optional options argument is passed to find when reloading so you may do eg record.reload (: lock => true) to reload the same record with an exclusive row lock.

When do you need to do reload? When you hold a object whose state may be changed by others.

5. Render: partial => 'shared / search', locals => (: objects => ...)

Why do we need locals? Partial is designed for reuse, so, you donot have to have the same name instance variable in your action, and locals make the reuse possible.

分类:Ruby 时间:2009-07-14 人气:455
blog comments powered by Disqus


  • Ruby class variable instance variable VS VS class instance variable 2010-11-28

    #!/usr/bin/ruby class A @@a = "a" # a class variable @b = "a" #a class instance variable attr_accessor :c def initialize(c) @c = c # an instance variable end class << self attr_accessor :b end def self.greeting puts @@a puts @b e

  • The assembly syntax of the Linux kernel 2011-09-03

    The GNU assembler gas is commonly used Linux system, assembler, which follows the AT & T assembly syntax. As the Linux kernel development based on the GNU tool chain, so the kernel compilation is also to follow the syntax. A conventional assembler sy

  • SERVLET classes and methods commonly used interfaces 2010-03-25

    Basic classes and interfaces a, javax.servlet.Servlet Interface abstract set is javax.servlet.Servlet servlet interface, it provides must be achieved by the Servlet class servlet engine identification and management approach set. Servlet interface to

  • PL \ SQL User's Guide and Reference 6.2 reproduced 2011-04-22

    Other OPEN-FOR statements can open the same query using a different cursor variables. Prior to re-open the cursor variable is not close it (but used multiple times for a static cursor OPEN operation, the system raises the predefined exception CURSOR_

  • ruby syntax tutorials 2010-08-02

    The first part of the Ruby language based Chapter § 1.1 Ruby Ruby language overview of the history Ruby language is Japanese inventor Yukihiro Matsumoto (Matsumoto Yukihiro), we affectionately called him "Matz". May be contrary to everyone's sur

  • config behind the scenes switched 2010-06-05

    That ruby is a bit weird syntax proper, which lack such a dynamic language syntax appear. But read some source code and found that the use of using the ruby is really different, as we said before, ruby may be drawn by each person is different. Is how

  • rails source code syntax highlighting and code display format 2010-06-24

    Code syntax highlighting rhighlightjs Official website: Relatively simple to use enviroment.rb config.gem 'romanvbabenko-rhighlightjs', :lib => 'rhighlightjs', :source => '' sudo ra

  • In the Linux platform to install and configure Ruby on Rails Detailed 2009-03-02

    ruby on rails recommend the production environment is running Linux / FreeBSD / Unix, or Unix family of operating systems, using lighttpd + FCGI solution. The following will be my Linux operating system, lighttpd + FCGI, MySQL database as an example,

  • Ruby User's Guide>> Simple examples 2009-03-10

    Let us write a factorial function of the calculation, n the mathematical definition of factorial is: n! = 1 (when n == 0) = N * (n-1)! (Otherwise) In Ruby, this may read as follows: def fact(n) if n == 0 1 else n * fact(n-1) end end You may end the r

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.152 (s). 10 q(s)