Skip to content

Instantly share code, notes, and snippets.

@Asher-
Created September 22, 2010 06:01
Show Gist options
  • Save Asher-/591221 to your computer and use it in GitHub Desktop.
Save Asher-/591221 to your computer and use it in GitHub Desktop.
VALUE rb_index = Qnil;
VALUE rb_key = Qnil;
VALUE rb_hash_descriptor_index_key = Qnil;
VALUE rb_hash_descriptor_index_keys_array = Qnil;
VALUE rb_args_array = Qnil;
RARG_Define(
/*----------------------------------------------*/
// { :index => [ <key> ] }
// { "index" => [ <key> ] }
// { :index => <key> }
// { "index" => <key> }
R_Descriptor( R_Parameter( R_Hash( R_Key( R_Type( R_SYMBOL | R_STRING ) ),
R_Data( R_MatchArray( rb_hash_descriptor_index_keys_array ) ),
R_MatchAny( rb_hash_descriptor_index_key ) ) ) ) ),
/*----------------------------------------------*/
// :index, <key>
// "index", <key>
R_Descriptor( R_Parameter( R_MatchType( R_SYMBOL | R_STRING,
rb_index ) ),
R_Parameter( R_MatchAny( rb_key ) ) ),
/*----------------------------------------------*/
// [ <arg> ]
R_Descriptor( R_Parameter( R_MatchArray( rb_args_array ) ) ),
/*----------------------------------------------*/
// <key>
R_Descriptor( R_Parameter( R_MatchAny( rb_key ) ) )
/*----------------------------------------------*/
)
RARG_Parse( argc, args );
if ( rb_index != Qnil
&& rb_key != Qnil ) {
// parse index/key pair normally
}
else if ( rb_hash_descriptor_index_key != Qnil
|| rb_hash_descriptor_index_keys_array != Qnil ) {
// { :index => key } or { :index => [ keys ] }
// iterate and pass :index pairs/sets individually to this function to be parsed
}
else if ( rb_args_array != Qnil ) {
// [ args ]
// pass each to this function to be parsed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment