🏋️♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] (pry) main: 0> default_array = []; | |
[2] (pry) main: 0> my_hash = Hash.new default_array; | |
[3] (pry) main: 0> my_hash[:hobbies] << 'dancing'; | |
[4] (pry) main: 0> my_hash[:skills] << 'php'; | |
[5] (pry) main: 0> my_hash[:hobbies] == my_hash[:skills] | |
=> true | |
[6] (pry) main: 0> my_hash[:hobbies] == default_array | |
=> true | |
[7] (pry) main: 0> default_array | |
=> ["dancing", "php"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] (pry) main: 0> my_hash = Hash.new { |hash, key| hash[key] = [] } | |
=> {} | |
[2] (pry) main: 0> my_hash[:hobbies] << 'swimming'; | |
[3] (pry) main: 0> my_hash[:skills] << 'java'; | |
[4] (pry) main: 0> my_hash[:hobbies] | |
=> ["swimming"] | |
[5] (pry) main: 0> my_hash[:hobbies].object_id | |
=> 70144893987080 | |
[6] (pry) main: 0> my_hash[:skills] | |
=> ["java"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.reflectiveCalls | |
import scala.language.postfixOps | |
import scala.reflect.Manifest | |
import scala.reflect.ClassTag | |
def |[T: ClassTag](x: T*) = new { def | = x.toArray } | |
val a = |(1, 2, 3)| | |
val b = |("a", "b", "c")| | |
val c = |(true, false)| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoSomeAction | |
def initialize(dependency_injection_arguments) | |
# ... | |
end | |
def call(optional_arguments) | |
# ... | |
end | |
private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import scala.collection.JavaConverters._ | |
import scala.collection.JavaConverters._ | |
scala> scalaList.asJava | |
res11: java.util.List[Int] = [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import scala.collection.JavaConversions._ | |
import scala.collection.JavaConversions._ | |
scala> val javaList: java.util.List[Int] = scalaList | |
javaList: java.util.List[Int] = [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def startpakkerCountForTelenor = startpakkerCount(Brands.Telenor) | |
def startpakkerCountForCBB = startpakkerCount(Brands.CBB) | |
def startpakkerCountForOne = startpakkerCount(Brands.One) | |
def startpakkerCountForColour = startpakkerCount(Brands.Colour) | |
private def startpakkerCount(brand: Brand) = startpakkerForBrand(brand) match { | |
case None => None | |
case Some(list) => Some(list.size) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClientsController < ActionController::API | |
def update_registration_number | |
update_registration_number_service.(registration_number) | |
render_success | |
rescue UpdateRegistrationNumber::RegistrationNumberAlreadyExist | |
render_error | |
end | |
# ... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CarDealer | |
def sell_car(client_id, car_id) | |
# queries | |
client = find_client(client_id) | |
car = find_car(car_id) | |
# services | |
oder_car_for_client(car, client) | |
prepare_an_invoice(car, client) | |
deliver_car(car, client) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
def rescue_exception(divider) | |
1 / divider | |
rescue ZeroDivisionError | |
end | |
def without_rescue(divider) | |
1 / divider | |
end |