Showing posts with label Environment. Show all posts
Showing posts with label Environment. Show all posts

Friday, July 31, 2009

Linux 环境变量显示和设置

$> export
export命令不带参数可以将系统的环境变量全部列出来,如果需要设置环境变量,
可以在/etc/profile, ~/.bash_profile, ~/.bashrc文件中设置。

一些标准的环境变量:
SHELL 默认shell
LANG 默认语言
PATH linux寻找命令的默认路径,一般包括/bin,/usr/bin,/sbin,/usr/sbin,
/usr/X11R6/bin, /opt/bin,/usr/local/bin等。用户可以自行添加,
MANPATH man手册的默认路径
INPUTRC 默认键盘映象,详见/etc/inputrc
BASH_ENV bash shell的环境变量,通常在~/.bashrc中
DISPLAY X窗口适用的控制台,DISPLAY=:0对应于控制台F7,DISPLAY=:1对应于
控制台F8,DISPLAY=server:0向远程计算机发送 GUI应用程序。
COLORTERM GUI中的默认终端,通常是gnome-terminal.
USER 自动设置当前登陆用户的用户名。
LONGNAME 通常设置为$USER
MAIL 设置特定$USR的标准邮件目录
HOSTNAME 设置为/bin/hostname的命令输出
HISTSIZE 设置为history命令记住的命令数

Reference:http://matt-u.javaeye.com/blog/411379

Friday, November 16, 2007

R4R and PR2 environment top-level method 学习笔记

R4R
Defining a top-level method
Suppose you define a method at the top level:


def talk
puts "Hello"
end

Who, or what, does the method belong to? It’s not inside a class or module definition block, so it doesn’t appear to be an instance method of a class or module. It’s not attached to any particular object (as in def obj.talk), so it’s not a singleton method. What is it?
By special decree (this is just the way it works!), top-level methods are private instance methods of the Kernel module.
That decree tells you a lot.
Because top-level methods are private, you can’t call them with an explicit receiver; you can only call them by using the implied receiver, self. That means self must be an object on whose method search path the given top-level method lies.

The default object (self) and scope
But every object’s search path includes the Kernel module, because the class Object mixes in Kernel, and every object’s class has Object as an ancestor. That means you can always call any top-level method, wherever you are in your program.
It also means you can never use an explicit receiver on a top-level method.
To illustrate this, let’s extend the talk example. Here it is again, with some code that exercises it:

def talk
puts "Hello"
end
puts "Trying 'talk' with no receiver..."
talk
puts "Trying 'talk' with an explicit receiver..."
obj = Object.new
obj.talk

The first call to talk succeeds; the second fails, because you’re trying to call a private method with an explicit receiver.
The rules concerning definition and use of top-level methods brings us all the way back to some of the bareword methods we’ve been using since as early as chapter1(R4R book). You’re now in a position to understand exactly how those methods work.

Programming Ruby 2nd
Top-Level Execution Environment
Many times in this book we’ve claimed that everything in Ruby is an object. However, we’ve used one thing time and time again that appears to contradict this—the top-level Ruby execution environment.
puts "Hello, World"
Not an object in sight. We may as well be writing some variant of Fortran or BASIC.
But dig deeper, and you’ll come across objects and classes lurking in even the simplest code.
We know that the literal "Hello, World" generates a Ruby String, so that’s one object. We also know that the bare method call to puts is effectively the same as self.puts. But what is self?
self.class ! Object
At the top level, we’re executing code in the context of some predefined object. When we definemethods, we’re actually creating (private) instancemethods for class Object.
This is fairly subtle; as they are in class Object, these methods are available everywhere.
And because we’re in the context of Object, we can use all of Object’s methods (including those mixed-in from Kernel) in function form. This explains why we
can call Kernel methods such as puts at the top level (and indeed throughout Ruby): these methods are part of every object. Top-level instance variables also belong to this top-level object.

命令行中定义的其实是定义在Kernel中的私有方法,并被Mix-in到Object类中成为其对象私有实例方法。因为class Module (< Object)和class Class (< Module)这3者的继承关系,所以控制台里定义的方法在module和class实例对象中可以调用。

Thursday, November 08, 2007

Rails development environment problem

在开发模式下,Rails的Models里的文件修改后会自动重载入,但是Models里require进来的Ruby lib和Rails lib下的文件有所修改是不会自动重载入的,必须需要重启Rails应该。

Sunday, August 26, 2007

Rails ActiveRecord Observer usage

要使Observer工作,第一种做法是在controller里声明, 这样unit test就无法加载此observer到console中


# app/models/flower_observer.rb
class FlowerObserver < ActiveRecord::Observer
observe Flower

def after_create(model)
# model.do_something!
end
end

# controller(s)
class FlowerController < ApplicationController
observer :flower_observer
end

第二种做法可以加载observer到console中:

# app/models/foo_bar.rb
class FooBar < ActiveRecord::Base
end

FooBarObserver.instance

最后一个方法是在config/environment.rb中加载此observer:

config.active_record.observers = :flower_observer


参考RobbyOnRails