Skip to content

Instantly share code, notes, and snippets.

View rosylilly's full-sized avatar
🕊️
Happy Hacking

Sho Kusano rosylilly

🕊️
Happy Hacking
View GitHub Profile
# frozen_string_literal: true
class PartialValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if options[:if] && !valuable(record, options[:if])
return if options[:unless] && valuable(record, options[:unless])
value.validate
value.errors.messages.each_pair do |attr, messages|
messages.each do |message|
@rosylilly
rosylilly / 00-actor.rb
Last active March 3, 2017 07:03
分かった気になる DCI 、ロミオとジュリエット編 Romeo & Juliette with DCI
# 役者クラス
#
# say: 役者は声を発する事ができる。
class Actor
def say(words)
puts words
end
end
@rosylilly
rosylilly / refinements.rb
Created January 5, 2014 07:33
refinements w/ block
class A
def say
puts "A"
end
end
module B
def self.role(klass, &block)
ref = refine(klass) { }
ref.module_eval(&block)
@rosylilly
rosylilly / gist:8013662
Last active December 31, 2015 16:29
ask.fm への解答
require 'unextend'
class Person
attr_accessor :husbund, :wife
def help(other)
...
end
def tell_love(other)
@rosylilly
rosylilly / article.rb
Created February 12, 2013 07:26
Answer for http://twitter.com/VoQn/status/301223276636692480 あえてまわりくどい書き方をしています。
# 記事クラス
class Article < AR::Base
belongs_to :user
end
@rosylilly
rosylilly / gist:4701807
Created February 3, 2013 13:35
これで治らないかな
FactoryGirl.define do
factory :user do
tasks do |user|
[
FactoryGirl.create(:task, user: user)
]
end
end
end
@rosylilly
rosylilly / jquery-tapp.js
Created September 13, 2012 06:28
jQuery-tapp
jQuery.fn.extend({
/**
* $('li').tapp() で console.debug に this を出力します。
*
* func を与えることで、func(this) を実行した結果を console.debug に出力します。
*
* @this {jQuery}
* @param {function(jQuery)=} func
* @return {jQuery}
*/
@rosylilly
rosylilly / new_type.rb
Created August 27, 2012 03:10
Newtype on Ruby
class Class
def new_type(&block)
new_class = self.dup
new_class.class_eval(&block) if block_given?
new_class
end
end
CArray = Array.new_type do
def example
@rosylilly
rosylilly / css-specificity.html
Created August 10, 2012 06:25
CSS の優先順位付けについて
<!DOCTYPE html>
<html>
<head>
<style>
p.a.b.c.d.e.f.g.h.i.j.k {
color: red;
}
p#a {
color: blue;
#!/usr/bin/env bash
exit 1