T_FLOAT);! ! // Checks if age is a Fixnum! Check_Type(age, T_FIXNUM);! ! // Checks if name is a String! Check_Type(name, T_STRING);! ! // Checks if options is a Hash! Check_Type(options, T_HASH); !
phrase = rb_str_new2("Hello, ");! ! // Append two Ruby strings together! rb_str_append(phrase, subject);! ! // Append a char * to a Ruby string! rb_str_cat2(phrase, "Something");! ! // Duplicate a Ruby string! VALUE copy = rb_str_dup(phrase);! ! // Get a substring from a Ruby string! VALUE without_hello = rb_str_substr(phrase, 7, 100);!
! // Push values to a Ruby array! rb_ary_push(array, rb_str_new2("One thing"));! rb_ary_push(array, rb_str_new2("Another thing"));! ! // Add a value to a specific position in a Ruby array! rb_ary_store(array, 2, rb_str_new2("A third thing"));! ! // Reverse a Ruby array! VALUE reversed = rb_ary_reverse(array);! ! // Create a Ruby string out of a Ruby array! VALUE string = rb_ary_join(array, rb_str_new2(", "));!
a value if so.! if(rb_block_given_p()) rb_yield(value)! ! // Same as above, but multiple values! if(rb_block_given_p()) rb_yield_values(value1, value2)! ! // Store a block into a variable and call it later.! VALUE block = rb_block_proc();! rb_funcall(block, rb_intern("call"), 2, value1, value2);!