Merge branch 'take-cheeze-reduce_new_obj'

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-06-23 19:51:52 +09:00
3 changed files with 26 additions and 16 deletions
+7 -16
View File
@@ -7,17 +7,6 @@ class Symbol
end
end
##
# call-seq:
# sym.length -> integer
#
# Same as <code>sym.to_s.length</code>.
def length
self.to_s.length
end
alias :size :length
##
# call-seq:
# sym.capitalize -> symbol
@@ -25,7 +14,7 @@ class Symbol
# Same as <code>sym.to_s.capitalize.intern</code>.
def capitalize
self.to_s.capitalize.intern
(self.to_s.capitalize! || self).to_sym
end
##
@@ -35,7 +24,7 @@ class Symbol
# Same as <code>sym.to_s.downcase.intern</code>.
def downcase
self.to_s.downcase.intern
(self.to_s.downcase! || self).to_sym
end
##
@@ -45,7 +34,7 @@ class Symbol
# Same as <code>sym.to_s.upcase.intern</code>.
def upcase
self.to_s.upcase.intern
(self.to_s.upcase! || self).to_sym
end
##
@@ -56,7 +45,9 @@ class Symbol
def casecmp(other)
return nil unless other.kind_of?(Symbol)
self.to_s.upcase <=> other.to_s.upcase
lhs = self.to_s; lhs.upcase!
rhs = other.to_s; rhs.upcase!
lhs <=> rhs
end
#
@@ -66,7 +57,7 @@ class Symbol
# Returns that _sym_ is :"" or not.
def empty?
self.to_s.empty?
self.length == 0
end
end
+16
View File
@@ -42,11 +42,27 @@ mrb_sym_all_symbols(mrb_state *mrb, mrb_value self)
return ary;
}
/*
* call-seq:
* sym.length -> integer
*
* Same as <code>sym.to_s.length</code>.
*/
static mrb_value
mrb_sym_length(mrb_state *mrb, mrb_value self)
{
mrb_int len;
mrb_sym2name_len(mrb, mrb_symbol(self), &len);
return mrb_fixnum_value(len);
}
void
mrb_mruby_symbol_ext_gem_init(mrb_state* mrb)
{
struct RClass *s = mrb->symbol_class;
mrb_define_class_method(mrb, s, "all_symbols", mrb_sym_all_symbols, MRB_ARGS_NONE());
mrb_define_method(mrb, s, "length", mrb_sym_length, MRB_ARGS_NONE());
mrb_define_method(mrb, s, "size", mrb_sym_length, MRB_ARGS_NONE());
}
void
+3
View File
@@ -19,14 +19,17 @@ end
assert("Symbol#capitalize") do
assert_equal :Hello, :hello.capitalize
assert_equal :Hello, :HELLO.capitalize
assert_equal :Hello, :Hello.capitalize
end
assert("Symbol#downcase") do
assert_equal :hello, :hEllO.downcase
assert_equal :hello, :hello.downcase
end
assert("Symbol#upcase") do
assert_equal :HELLO, :hEllO.upcase
assert_equal :HELLO, :HELLO.upcase
end
assert("Symbol#casecmp") do