Top Level Namespace

Defined Under Namespace

Modules: GreeErr, GreeJson, RestObject Classes: Array, GreeLog, Hash

Constant Summary collapse

INFINITY =
1.0/0
NaN =
0.0/0

Instance Method Summary collapse

Instance Method Details

#current_function_nameObject

Returns the name of the function from which this method was called, by looking at the call stack. If call stack is empty, returns “(anonymous)”

def foo
    puts current_function_name
end

foo -> "foo"

current_function_name -> "(anonymous)"

Used for logging and error reporting, so that generic code can record the name of the currently running function.



44
45
46
# File 'lib/rest-object/gree_ruby_extensions.rb', line 44

def current_function_name
    return caller()[0] =~ /in `([^']+)'/ ? $1 : '(anonymous)'
end

#previous_function_nameObject

Returns the name of the function two levels down in the call stack. If call stack has insufficient depth, returns “(anonymous)”

def foo
    puts previous_function_name
end

def bar
    foo
end

bar -> "bar"

foo -> "(anonymous)"

previous_function_name => "(anonymous)"

Used for setting up a centralized error handler that calls a centralized logger.



67
68
69
70
71
72
73
# File 'lib/rest-object/gree_ruby_extensions.rb', line 67

def previous_function_name
    if caller().length < 2
        return '(anonymous)'
    else
        return caller()[1] =~ /in `([^']+)'/ ? $1 : '(anonymous)'
    end
end

#testObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rest-object/gree_err.rb', line 65

def test
    GreeLog.handler=Logger.new(
        File.join(File.expand_path(File.dirname(__FILE__)), 'test-' + Time.now.strftime('%Y-%m-%d-%H%M%S') + '.log')
    )

    begin
        GreeErr.raise 'this is an error message'
    rescue
    end

    begin
        GreeErr.raise ArgumentError
    rescue
    end

    begin
        GreeErr.raise ArgumentError, 'this is a message for ArgumentError exception'
    rescue
    end

    begin
        GreeErr.raise
    rescue
    end
end