Skip to content

Instantly share code, notes, and snippets.

my_proc = Proc.new do |e|
puts "this is #{e}"
end
my_proc.call(2)
my_proc.(2)
my_proc[2]
my_proc === 2
@cawel
cawel / gist:c1e4bc203ab33c95e607
Last active August 29, 2015 14:09
blog-proc2
def run_proc(p)
p.call
end
name = "Fred"
my_proc = proc { puts name }
name = "Marc"
run_proc my_proc
@cawel
cawel / gist:eb531f95a63510a5686d
Last active August 29, 2015 14:09
blog-nodejs
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
class Robot
def move(&block)
instance_eval( &block )
end
def up;
puts “u“;
end
def down;
@cawel
cawel / gist:edffa2085b8c3a7a0de9
Created November 19, 2014 22:49
blog-quiz-intermediate
class A
attr_accessor :var
def method
var = 45
end
end
a = A.new
a.method
puts a.var
@cawel
cawel / gist:506cafa394afa170ef62
Created November 19, 2014 22:59
blog-quiz-easy-10
value = compute_value
value = (value > CONSTANT) ? value : CONSTANT
@cawel
cawel / gist:df6bec78bd0822ccf81c
Created November 19, 2014 23:05
blog-quiz-easy-9
require 'rubygems'
require 'fileutils'
puts File.expand_path(File.dirname(__FILE__))
FileUtils.mkdir 'test'
FileUtils.chdir 'test'
puts File.expand_path(File.dirname(__FILE__))
@cawel
cawel / gist:494fd7f4df8b4ab89fb7
Created November 19, 2014 23:11
blog-quiz-easy-8
hash = {:language => 'ruby', :author => 'martin'}
puts hash['language']
@cawel
cawel / gist:ed2d618931e469416051
Created November 19, 2014 23:12
blog-quiz-easy-8
require 'rubygems'
require 'active_support'
hash = HashWithIndifferentAccess.new({:language => 'ruby', :author => 'martin'})
p hash['language']
@cawel
cawel / gist:69131717ccbe95700e67
Created November 19, 2014 23:22
blog-quiz-easy-7
ary = [1,2,3]
ary.each do |element|
element += 1
end
puts ary