Skip to content

Instantly share code, notes, and snippets.

View serradura's full-sized avatar
🎯
Focusing

Rodrigo Serradura serradura

🎯
Focusing
View GitHub Profile
@serradura
serradura / fp_01.rb
Last active January 17, 2019 14:51
Examples of how Ruby 2.6 is more functional than ever! 👏🎉🚀
raise 'Wrong Ruby version!' unless RUBY_VERSION >= '2.6.0'
module Strings
Trim = -> str { String(str).strip }
Replace = -> (sub, new_sub, str) { String(str).gsub(sub, new_sub) }
LowerCase = -> str { String(str).downcase }
end
# -- Alternative syntax --
Slugify = # Slugify =
@serradura
serradura / Rakefile
Last active December 18, 2018 15:34
Exemplo de rake task com Functional Objects (Rubyconf Brasil 2018)
class TaskArgumentsCalculator
def initialize(operator)
@operator = operator
end
def call(_task, args)
puts map_numbers(args).reduce(&@operator)
end
@serradura
serradura / Rakefile
Last active December 18, 2018 15:34
Exemplo de rake task numa abordagem Procedural |> Funcional (Rubyconf Brasil 2018)
ArgAsNumber = -> (args) do
-> key { args[key].to_f }
end
CalculateTaskArgumentsWith = -> (operator) do
-> (task, args) do
arg_as_number = ArgAsNumber.(args)
puts [:a, :b].map(&arg_as_number).reduce(&operator)
@serradura
serradura / example_1.rb
Last active October 19, 2018 16:37
Example of how to make APIs tests (end-to-end) using Ruby.
# Runtime dependency:
# gem install bundler --no-ri --no-rdoc
# How to run:
# ruby example_1.rb
require "bundler/inline"
gemfile do
source "https://rubygems.org"
@serradura
serradura / README.md
Last active January 18, 2019 13:20
Simple authorization library and role managment for Ruby - https://rubygems.org/gems/u-authorization

µ-authorization

Simple authorization library and role managment for Ruby.

Prerequisites

Ruby >= 2.2.2

Installation

<!DOCTYPE html>
<html>
<head>
<title>jQuery.behavior</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<a href="01.html">01</a> | <a href="02.html">02</a> | <a href="03.html">03</a> | <a href="04.html">04</a> | <a href="05.html">05</a>
@serradura
serradura / README.md
Last active July 23, 2020 13:45
ORM (225 LOC and ~510 LOC of tests) - An Object-relational mapping implementation using only the Ruby standard library.
@serradura
serradura / README.md
Last active April 21, 2022 19:33
Microtest - A xUnit family unit testing microframework for Ruby. (https://rubygems.org/gems/u-test)

µ-test (Microtest)

A xUnit family unit testing microframework for Ruby.

Prerequisites

Ruby >= 2.2.2

Installation

module Foo
A = 1
B = 2
def a1
A
end
def b1
B
module LazyLogger
extend self
attr_accessor :output
def log(&callback)
@log_actions ||= []
@log_actions << callback
end