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
str = "神" + "Äが".unicode_normalize(:nfd) | |
# => "神Äが" | |
str.size | |
# => 5 | |
str2 = str.each_grapheme_cluster.map {|s| s.size > 1 ? s.unicode_normalize : s }.join | |
# => "神Äが" | |
str2.size | |
# => 3 |
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
/* global console */ | |
/* eslint complexity: ["error", 2] */ | |
!function() { | |
(M => ((f => (p => f(a => (p(p))(a))) (p => f(a => (p(p))(a))))(f => n => (t => n > 0 && t())(() => (() => (str => console.log(str || n))((str => n % 5 ? str : `${str}Buzz`) ((str => n % 3 ? str : `${str}Fizz`)(""))))(f(n - 1)))))(M))(100); | |
}(); |
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
function* fizzbuzz() { | |
let n = 1; | |
while (true) { | |
yield n++; | |
yield n++; | |
yield "Fizz"; n++; | |
yield n++; | |
yield "Buzz"; n++; | |
yield "Fizz"; n++; | |
yield n++; |
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
return hello, world! | |
BEGIN { | |
using Module.new { | |
refine(Object) { | |
alias hello itself | |
alias world! itself | |
} | |
} |
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
$ gem i with_refinements |
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
= RubyVM::AST | |
(from ruby core) | |
------------------------------------------------------------------------ | |
= Class methods: | |
parse, parse_file |
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
hi | |
# hi | |
BEGIN { | |
using Module.new { | |
refine(Object) do | |
def hi | |
puts "hi" | |
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
$ ruby -e '$~=1' | |
Traceback (most recent call last): | |
-e:1:in `<main>': wrong argument type Integer (expected MatchData) (TypeError) |
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
# NilClass = FalseClassで死ぬのでこの解は弱い | |
# 指摘: https://twitter.com/mametter/status/1001792845961834497 | |
# x.nil? を殺す | |
def nil.nil? | |
false | |
end | |
# x == nil を殺す | |
def nil.==(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
module AndOr | |
refine(Object) do | |
def and(o) | |
if self | |
o | |
else | |
self | |
end | |
end |