ruby
ãã³ããã¼ã¯ã¨ãããããããªããã©ãtimeã¨ããã³ãã³ãã§ã§ããã¿ãããªã®ã§ãã¡ãã£ã¨ãã£ã¦ã¿ããbenchrmark.rb #!/usr/bin/env ruby puts (1..1000).to_a.inject(:+) benchmark.io #!/usr/bin/env io Range setRange(1, 1000) asList reduce(+) print â¦
aereal/music-chord · GitHub ç絡çã«Music::Chordã¨åã¥ãã¾ããããããããã°ãæ°ããã¾ããããã¯ãOSã®APIãå©ãã¦é³å£°ãåçããã¨ããããªãã°ããããã®ã§ã¯ãªãã¦ãæ§æé³ããã³ã¼ããã¼ã ã¨ããå¾ãã¨ãããããã£ãç¨éã«ä½¿ãã¾ãã ããããèâ¦
12é²æ°ãæ±ããã¨ãããªã«ãã class ::Fixnum def duo self % 12 end end ã¨ãããããããããã¨ã¯éæã§ããã®ã§ããã¨ããã
module ::Boolean def then self end def else self end end class ::TrueClass include Boolean def then yield self end def else self end end class ::FalseClass include Boolean def then self end def else yield self end end ãªãã¡ã¬ã³ã¹ã« # -> Bâ¦
def import(feature, as={}) ret = require feature self.class.instance_eval do as.each do |(orig, dest)| c = const_get(orig) remove_const(orig) if const_defined?(orig) const_set(dest, c) end end unless as.empty? ret end import "date", :Date â¦
def get_each_const(const, context=::Object) const.to_s.split(/::/).inject(context) {|parent, c| parent.const_get(c) } end module Foo module Bar module Hoge module Fuga end end end end bar = get_each_const "Foo::Bar" # -> Foo::Bar fuga = geâ¦
ã²ã¨ãã§æ¸ãã¦ããããã¬ãã¬ãã«ä½ã£ã¦ããããã§ããªããã©ãæ°ãã¤ããããã«ãã¦ãããã¨ã¨ãã Tab indent, No space indent ã¿ãã¤ã³ãã³ãã«æ±ºãæã¡ãã¦ããã°ãè¿ãå°æ¥ã«èªåãã¤ã³ãã³ãå¹ 8ã«ç®è¦ãã¦ããã¨ãã£ã¿ã®è¨å®ããããã°ããã ã¤ã³ãâ¦
Config = { # 対å¿ããã¡ãã£ã¢ã¿ã¤ãã®æ¡å¼µå :typemap => %w(xhtml html atom json) } class Resource Config[:typemap].each do |i| # Resource#to_xhtml, Resource#to_html, ... ãå®ç¾©ãã define_method("to_#{i}") do # Resource#to_xml ã¯ã³ã¢ã§å¯¾å¿â¦
begin require "dl/win32" rescue LoadError require "Win32API" end def alert(wnd, text, caption, mode=0) msgbox = Win32API.new("user32", "MessageBox", %w(p p p i), "i") msgbox.call(wnd, text, caption, mode) end if $0 == __FILE__ class Numeriâ¦
ERB ã Web ã¢ããªã±ã¼ã·ã§ã³ã®ãã¥ã¼ã«ä½¿ãã¨ããªããã«ãå¤æ°ã¨ãã使ãã¨ãã«ããèããªãã¨ãä½è¨ãªã¡ã½ãããå¼ã°ããããããã©ããªã®ã§ã def render_erb(template, vars={}) require "erb" obj = Object.new obj.class.instance_eval do vars.each dâ¦
ãã¾ããããªããã©ã a,b,c,d,... ã¨ããã¢ã«ãã¡ãããã®ç¾ å (ã¹ã¤ã«ã¢ã«ãã¡ããããããªãã¦ããããã©) ããã£ã¦ãããããã¨ã®ã¤ã³ããã¯ã¹ã¨åãã¤ã³ããã¯ã¹ä»¥å¤ã«ã©ã³ãã ã«é ç½®ãããã¨ããã½ã¼ãããã£ã¦ã¿ãã alphabet = ("a".."z").to_a.sortâ¦