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
# 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| |
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
# 役者クラス | |
# | |
# say: 役者は声を発する事ができる。 | |
class Actor | |
def say(words) | |
puts words | |
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 A | |
def say | |
puts "A" | |
end | |
end | |
module B | |
def self.role(klass, &block) | |
ref = refine(klass) { } | |
ref.module_eval(&block) |
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 'unextend' | |
class Person | |
attr_accessor :husbund, :wife | |
def help(other) | |
... | |
end | |
def tell_love(other) |
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 Article < AR::Base | |
belongs_to :user | |
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
FactoryGirl.define do | |
factory :user do | |
tasks do |user| | |
[ | |
FactoryGirl.create(:task, user: user) | |
] | |
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
jQuery.fn.extend({ | |
/** | |
* $('li').tapp() で console.debug に this を出力します。 | |
* | |
* func を与えることで、func(this) を実行した結果を console.debug に出力します。 | |
* | |
* @this {jQuery} | |
* @param {function(jQuery)=} func | |
* @return {jQuery} | |
*/ |
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 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 |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
p.a.b.c.d.e.f.g.h.i.j.k { | |
color: red; | |
} | |
p#a { | |
color: blue; |
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
#!/usr/bin/env bash | |
exit 1 |