lib/rubype.rb in rubype-0.2.4 vs lib/rubype.rb in rubype-0.2.5
- old
+ new
@@ -1,5 +1,7 @@
+require 'rubype/ordinal'
+
# Builtin Contracts
class Any; end
module Boolean; end
TrueClass.send(:include, Boolean)
FalseClass.send(:include, Boolean)
@@ -20,20 +22,23 @@
self
end
end
class Method
+ # @return [Hash]: { [ArgInfo_1, ArgInfo_2, ... ArgInfo_n] => RtnInfo }
def type_info
if methods_hash = Rubype.typed_method_info[owner]
methods_hash[name]
end
end
+ # @return [Array<Class, Symbol>]: [ArgInfo_1, ArgInfo_2, ... ArgInfo_n]
def arg_types
type_info.first.first if type_info
end
+ # @return [Class, Symbol]: RtnInfo
def return_type
type_info.first.last if type_info
end
end
@@ -78,13 +83,13 @@
def assert_arg_type(meth_caller, meth, args, type_infos)
args.zip(type_infos).each.with_index(1) do |(arg, type_info), i|
case type_check(arg, type_info)
when :need_correct_class
raise ArgumentTypeError,
- "Expected #{meth_caller.class}##{meth}'s #{i}th argument to be #{type_info} but got #{arg.inspect} instead"
+ "Expected #{meth_caller.class}##{meth}'s #{i}#{ordinal(i)} argument to be #{type_info} but got #{arg.inspect} instead"
when :need_correct_method
raise ArgumentTypeError,
- "Expected #{meth_caller.class}##{meth}'s #{i}th argument to have method ##{type_info} but got #{arg.inspect} instead"
+ "Expected #{meth_caller.class}##{meth}'s #{i}#{ordinal(i)} argument to have method ##{type_info} but got #{arg.inspect} instead"
end
end
end
# @param caller [Module]