Skip to content

Instantly share code, notes, and snippets.

def call(env)
request = Rack::Request.new(env)
# env["REQUEST_METHOD"]
verb = request.request_method #=> GET, POST, PUT, etc.
# env["REQUEST_METHOD"] == "POST"
request.post?
# env["PATH_INFO"]
path = request.path_info
# env["rack.session"]
request.session # access to the session object, if using the
require "rack/handler/puma"
class AnotherRackApp
def call(env)
http_verb = env["REQUEST_METHOD"]
path = env["PATH_INFO"]
status = 200
headers = {"Content-Type" => "text/html"}
body = ["got #{http_verb} <b>request</b> from <strong>#{path}</strong> path"]
[status, headers, body]
run ->(env) { [200, {}, ["I respond to all #{env["REQUEST_METHOD"]} request"]] }
require "rack"
app = Proc.new { |env| [200, {}, ["I respond to all request"]] }
Rack::Handler::WEBrick.run app, Port: 9292
class MarkRuby
def div(text = "", options = {}, &block))
html_tag(:div, text = "", options = {}, &block)
end
def body(text = "", options = {}, &block))
html_tag(:body, text = "", options = {}, &block)
end
def html(text = "", options = {}, &block))
class MarkRuby
def initialize(&block)
@curent_indentation = 0
@html = ""
html(&block)
end
def method_missing(method_name, *args, &block)
text = args.shift if args[0].is_a? String
html_tag(method_name, text, *args, &block)
<html>
<body id="body_id"_>
<div id="container">
<ul class="content">
<li class="active">Item 1</li>
<li>Item 2</li>
</ul>
</div>
</body>
</html>
mark_ruby do
body id: :body_id do
div id: :container do
ul class: :content do
li "Item 1", class: :active
li "Item 2"
end
end
end
end
describe Array do
describe "includes_subset?" do
it "finds subsets" do
a = [1,2,3,4,5]
b = [1,2]
expect(a.includes_subset?(b)).to eq(true)
end
end
end
class Person < ActiveRecord::Base
validates :email_confirmation, presence: true
validates :name, length: { minimum: 2 }
validates :bio, length: { maximum: 1000,
too_long: "%{count} characters is the maximum allowed" }
end