Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
ascendbruce / gist:7070911
Created October 20, 2013 15:13
Ruby get current file full path (absolute path)
File.expand_path(File.dirname(__FILE__))
# If you want to require some files in different directory, in ruby 1.9, you may want to use:
require_relative "../xxxlib"
@ascendbruce
ascendbruce / gist:7070884
Created October 20, 2013 15:11
Ruby throw catch example
error = catch(:error) do
throw :error, "params uuid required" if uuid.blank?
throw :error, "params lang required" unless params.include?("lang")
end
@ascendbruce
ascendbruce / gist:7070842
Created October 20, 2013 15:08
Markdown table example

source

|name|score|
|:---|----:|
|john|   96|
|wang|   88|

output

name score
@ascendbruce
ascendbruce / gist:7009252
Created October 16, 2013 15:10
Ruby File open read/write examples
File.open("/usr/local/widgets/data").each do |line|
    puts line if line =~ /blue/
end



logfile = File.new("/tmp/log", "w")

logfile.close