Exemplo n.º 1
0
static mrb_value
mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
{
  //if (FL_TEST(klass, FL_SINGLETON)) {
  if (mrb_type(klass) == MRB_TT_SCLASS) {
    mrb_value s = mrb_usascii_str_new2(mrb, "#<");
    mrb_value v = mrb_iv_get(mrb, klass, mrb_intern(mrb, "__attached__"));

    mrb_str_cat2(mrb, s, "Class:");
    switch (mrb_type(v)) {
      case MRB_TT_CLASS:
      case MRB_TT_MODULE:
        mrb_str_append(mrb, s, mrb_inspect(mrb, v));
        break;
      default:
        mrb_str_append(mrb, s, mrb_any_to_s(mrb, v));
        break;
    }
    mrb_str_cat2(mrb, s, ">");

    return s;
  }
  else {
    struct RClass *c = mrb_class_ptr(klass);
    const char *cn = mrb_class_name(mrb,  c);

    if (!cn) {
      char buf[256];


      switch (mrb_type(klass)) {
        case MRB_TT_CLASS:
          snprintf(buf, 256, "#<Class:%p>", c);
          break;

        case MRB_TT_MODULE:
          snprintf(buf, 256, "#<Module:%p>", c);
          break;

        default:
          break;
      }
      return mrb_str_dup(mrb, mrb_str_new_cstr(mrb, buf));
    }
    else {
      return mrb_str_dup(mrb, mrb_str_new_cstr(mrb, cn));
    }
  }
}
Exemplo n.º 2
0
static mrb_value
false_to_s(mrb_state *mrb, mrb_value obj)
{
    return mrb_usascii_str_new2(mrb, "false");
}
Exemplo n.º 3
0
static mrb_value
true_to_s(mrb_state *mrb, mrb_value obj)
{
    return mrb_usascii_str_new2(mrb, "true");
}