This file contains 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
hash = [{id: 1, name: 'taro', old: 22, sex: 'men'}, | |
{id: 2, name: 'hanako', old: 22, sex: 'woman'}, | |
{id: 3, name: 'taro', old: 24, sex: 'men'}, | |
{id: 4, name: 'taro', old: 24, sex: 'woman'}, | |
{id: 5, name: 'taro', old: 22, sex: 'woman'}, | |
] | |
p hash.uniq { |h| [h[:name], h[:old]] } | |
# => [{:id=>1, :name=>"taro", :old=>22, :sex=>"men"}, {:id=>2, :pname=>"hanako", :old=>22, :sex=>"woman"}, {:id=>3, :name=>"taro", :old=>24, :sex=>"men"}] |
This file contains 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
ary = [1, 10, 2, 5, 8, 4, 6] | |
ary.each_with_index.max[1] |
This file contains 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
a = {c: 3, b: 2, dd: 5, a: 1} | |
p a.sort.to_h |
This file contains 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
# メソッド内で | |
value = foo_method | |
return if value.nil? | |
# 下でも一緒 | |
value = foo_method.tap { |e| return if e.nil?} |
This file contains 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
AllCops: | |
Exclude: | |
- 'db/schema.rb' | |
- 'vendor/**/*' | |
- 'db/migrate/**/*' | |
Metrics/LineLength: | |
Max: 120 | |
Metrics/CyclomaticComplexity: |
This file contains 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 'forwardable' | |
class A | |
extend Forwardable | |
def_delegators :@ary, :size, :[]=, :[], :<<, :to_s, :inspect | |
def initialize | |
@ary = [] | |
end | |
end |
This file contains 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
find . -type f | grep -v git | awk -F/ '{t=" |---"}n==$2{printf "%s%s\n",t,$3}n!=$2&&$3!=""{n=$2;printf "%s \n%s%s\n",$2,t,$3}n!=$2&&$3==""{print $2}' | awk '/^ /{printf "| %s\n", $0} /^[^ ]/{printf "|--%s\n", $1}' | gtac | awk 'BEGIN{n=0} n==1{print $0}n==0{printf " %s\n",$2}n==0&&$2==""{print}$2==""{n=1}END{print "."}' | gtac | grep -v ' $' |
This file contains 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
module A | |
class << self | |
def setup! | |
@config = 'config' | |
end | |
def setup | |
@config | |
end |
This file contains 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 A | |
CONFIGURES = %i(user mail pass).freeze | |
def initialize(config = {}) | |
CONFIGURES.each do |e| | |
instance_variable_set(:"@#{e}", config[e] || 'nil') | |
end | |
end | |
end |
This file contains 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 Object | |
def current_method_name | |
caller.first.match(/`(?<method_name>.*)'/)[:method_name] | |
end | |
end | |
puts current_method_name #=> "<main>" |
OlderNewer