Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am mertguldur on github.
  • I am mguldur (https://keybase.io/mguldur) on keybase.
  • I have a public key ASBsh2JJjsKAD-JfPI292QIe8ySgesMI9LPmztj_cldbUwo

To claim this, I am signing this object:

@mertguldur
mertguldur / memoize.rb
Created February 17, 2017 02:44
Interactor#call memoization
module Interactors
class Base
MEMOIZATION_CACHE = {}
def self.memoize
method_name = :call
method = instance_method(method_name)
class_name = method.owner.name
define_method(method_name) do |*args|
@mertguldur
mertguldur / flatten.rb
Created February 15, 2017 02:43
Array Flatten
def flatten(array)
result = []
array.each do |element|
if element.is_a?(Array)
result += flatten(element)
else
result << element
end
end
result
@mertguldur
mertguldur / gist:b4528d889e1fc013926b
Last active August 29, 2015 14:22
Command line and Git commands

Command line

pwd

Look up the current directory.

ls
@mertguldur
mertguldur / gist:16d1ec347cfdf7a76d97
Last active August 29, 2015 14:22
Address book specification

Address book

This will be a command line program for managing and searching contacts in an address book.

How to run Ruby code

  1. Write Ruby code in a file <filename>.rb

  2. On command line, run

class ProductsController < ApplicationController
def show
product = Product.find(params[:id])
respond_to do |format|
format.html { render locals: { product: product } }
format.json { render json: product }
format.xml { render locals: { product: product } }
end
end
### sort vs sort! - what's the difference between these, and what are their return values?
# sort returns a new structure but doesn't modify the given one
# where as sort! modifies the given structure and returns it
### splat - give an example of using splat to eat function args, another to call a function and provide the args with splat
def foo1(arg1, *args)
args
end