String str = "This is a string." puts str # => This is a string. str = "This is another string." puts str # => This is another string. str = 65535 # => 例外発生
attr_型付accessor({:foo => String}) とかすると def foo @foo end def foo=(value) if value.instance_of?(String) raise(TypeError) end @foo = value end みたいなコードになるような感じ?(なんか違う気もする…)
便乗質問 ruby 1.6.3 (2001-03-19) [i386-cygwin]で a = `dir`.to_a ってやるとcommand not found: dirってエラーが出て a = `cmd.exe /c dir /b`.to_a ってやるとうまくいくんだけど。前者の方法では呼べないの?
@gaTable.collect! do |tb| tb = [] ld = @data.dup 0.upto(@data.size-1) do |lp| n = rand(ld.size) tb.push(ld[n]) ld.delete_at(n) end p tb tb ##<=要素にしたいものを最後に返す end
class Module def procedure(func) module_eval %{ alias _func_#{func} #{func} def #{func}(*args); _func_#{func}(*args); nil; end } end end def procedure(func) class << self; self; end.procedure(func) end
############
def set_pass @pass = get_pass_from_dokka end procedure :set_pass