Skip to content
Browse files

adding the to_s method

  • Loading branch information...
1 parent 21aaa8f commit bafa76dbb7f6be1779f474d0d43aa95c24575cef @tenderlove committed Dec 16, 2009
Showing with 14 additions and 0 deletions.
  1. +9 −0 ext/stree/stree_string.c
  2. +5 −0 test/test_string.rb
View
9 ext/stree/stree_string.c
@@ -47,6 +47,14 @@ static VALUE get(VALUE self, VALUE index)
return Qnil;
}
+static VALUE to_s(VALUE self)
+{
+ LST_String * ptr;
+
+ Data_Get_Struct(self, LST_String, ptr);
+ return rb_str_new2(lst_string_print(ptr));
+}
+
void Init_stree_string()
{
cStreeString = rb_define_class_under(cStree, "String", rb_cObject);
@@ -55,4 +63,5 @@ void Init_stree_string()
rb_define_method(cStreeString, "initialize", initialize, 1);
rb_define_method(cStreeString, "bytesize", bytesize, 0);
rb_define_method(cStreeString, "[]", get, 1);
+ rb_define_method(cStreeString, "to_s", to_s, 0);
}
View
5 test/test_string.rb
@@ -20,5 +20,10 @@ def test_square
end
end
end
+
+ def test_to_s
+ sstr = Stree::String.new("foo")
+ assert_equal 'foo', sstr.to_s
+ end
end
end

0 comments on commit bafa76d

Please sign in to comment.
Something went wrong with that request. Please try again.