Exemplo n.º 1
0
Arquivo: hash.c Projeto: denji/mruby
static mrb_value
mrb_hash_has_key(mrb_state *mrb, mrb_value hash)
{
  mrb_value key;

  mrb_get_args(mrb, "o", &key);
  return mrb_hash_has_keyWithKey(mrb, hash, key);
}
Exemplo n.º 2
0
mrb_value
mrb_hash_rassoc(mrb_state *mrb, mrb_value hash)
{
  mrb_value key, value, has_key;

  mrb_get_args(mrb, "o", &key);
  has_key = mrb_hash_has_keyWithKey(mrb, hash, key);
  if (mrb_test(has_key)) {
    value = mrb_hash_get(mrb, hash, key);
    return mrb_assoc_new(mrb, value, key);
  }
  else {
    return mrb_nil_value();
  }
}
Exemplo n.º 3
0
mrb_value
mrb_hash_assoc(mrb_state *mrb, mrb_value hash)
{
  mrb_value key, value, has_key;

  mrb_get_args(mrb, "o", &key);
  if (mrb_nil_p(key))
    mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");

  has_key = mrb_hash_has_keyWithKey(mrb, hash, key);
  if (mrb_test(has_key)) {
    value = mrb_hash_get(mrb, hash, key);
    return mrb_assoc_new(mrb, key, value);
  }
  else {
    return mrb_nil_value();
  }
}