Get the name of the script that is running
script-name: does [system/options/script]
11308 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
script-name: does [system/options/script]
module Kernel private def this_method_name caller[0] =~ /`([^']*)'/ and $1 end end class Foo def test_method this_method_name end end puts Foo.new.test_method # => test_method
function string_to_underscore_name($string) { $string = preg_replace('/[\'"]/', '', $string); $string = preg_replace('/[^a-zA-Z0-9]+/', '_', $string); $string = trim($string, '_'); $string = strtolower($string); return $string; }
def checked?( *args ) if args.length == 3 object, method, value = args if params[object] && params[object][method] && params[object][method] == value 'checked' end elsif args.length == 2 name, value = args if params[name] && params[name] == value true end end end
<%= radio_button 'person', 'age', '12', :checked => checked?( 'person', 'age', '12' ) %>
Black #000000 Silver #C0C0C0 Gray #808080 White #FFFFFF Maroon #800000 Red #FF0000 Purple #800080 Fuchsia #FF00FF Green #008000 Lime #00FF00 Olive #808000 Yellow #FFFF00 Navy #000080 Blue #0000FF Teal #008080 Aqua #00FFFF
import re def cw2us(x): # capwords to underscore notation return re.sub(r'(?<=[a-z])[A-Z]|(?<!^)[A-Z](?=[a-z])', r"_\g<0>", x).lower() def mc2us(x): # mixed case to underscore notation return cw2us(x) def us2mc(x): # underscore to mixed case notation return re.sub(r'_([a-z])', lambda m: (m.group(1).upper()), x) def us2cw(x): # underscore to capwords notation s = us2mc(x) return s[0].upper()+s[1:]
>>> cw2us("PrintHTML") 'print_html' >>> cw2us("IOError") 'io_error' >>> cw2us("SetXYPosition") 'set_xy_position' >>> cw2us("GetX") 'get_x'