🖥

#python で #ruby の instance#methods みたいな感じで全てのメソッドを表示するらしき例

2019/04/07に公開

python

メソッドではなく attributes を表示するという扱いではあるらしい (詳細不明)

Python dir() - Python Standard Library

The dir() method tries to return a list of valid attributes of the object.

>>> dir("a")
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> "a".title()
'A'

ruby

[1] pry(main)> "a".methods
=> [:include?,
 :%,
 :*,
 :+,
 :unicode_normalize,
 :shellsplit,
 :to_c,
 :unicode_normalize!,
 :unicode_normalized?,
 :shellescape,
 :count,
 :partition,
 :unpack,
 :next,
 :encode,
 :encode!,
 :casecmp,
 :insert,
 :bytesize,
 :match,
 :succ!,
 :next!,
 :upto,
 :index,
 :rindex,
 :replace,
 :clear,
 :+@,
 :-@,
 :getbyte,
 :chr,
 :<=>,
 :<<,
 :byteslice,
 :scrub,
 :setbyte,
 :==,
 :===,
 :scrub!,
 :=~,
 :upcase,
 :[],
 :[]=,
 :dump,
 :upcase!,
 :downcase,
 :capitalize,
 :swapcase,
 :hex,
 :empty?,
 :eql?,
 :swapcase!,
 :bytes,
 :oct,
 :downcase!,
 :capitalize!,
 :reverse!,
 :chars,
 :codepoints,
 :split,
 :lines,
 :concat,
 :end_with?,
 :crypt,
 :reverse,
 :start_with?,
 :center,
 :freeze,
 :inspect,
 :intern,
 :chomp,
 :sub,
 :gsub,
 :prepend,
 :rjust,
 :ord,
 :lstrip,
 :rstrip,
 :scan,
 :length,
 :size,
 :chomp!,
 :succ,
 :sub!,
 :chop,
 :chop!,
 :ljust,
 :strip!,
 :lstrip!,
 :tr_s,
 :delete,
 :strip,
 :tr!,
 :to_str,
 :to_sym,
 :gsub!,
 :each_line,
 :squeeze,
 :each_char,
 :to_s,
 :to_i,
 :tr,
 :slice!,
 :each_byte,
 :encoding,
 :each_codepoint,
 :tr_s!,
 :delete!,
 :rstrip!,
 :rpartition,
 :to_f,
 :b,
 :sum,
 :slice,
 :squeeze!,
 :to_r,
 :force_encoding,
 :valid_encoding?,
 :ascii_only?,
 :hash,
 :to_json,
 :to_json_raw,
 :to_json_raw_object,
 :<,
 :>,
 :<=,
 :>=,
 :between?,
 :pry,
 :__binding__,
 :pretty_print,
 :pretty_print_cycle,
 :pretty_print_instance_variables,
 :pretty_print_inspect,
 :tap,
 :public_send,
 :instance_variables,
 :instance_variable_set,
 :instance_variable_defined?,
 :remove_instance_variable,
 :private_methods,
 :kind_of?,
 :is_a?,
 :instance_variable_get,
 :method,
 :public_method,
 :singleton_method,
 :instance_of?,
 :extend,
 :define_singleton_method,
 :to_enum,
 :enum_for,
 :pretty_inspect,
 :!~,
 :respond_to?,
 :object_id,
 :display,
 :send,
 :nil?,
 :class,
 :singleton_class,
 :clone,
 :dup,
 :itself,
 :taint,
 :tainted?,
 :untaint,
 :untrust,
 :trust,
 :untrusted?,
 :methods,
 :protected_methods,
 :frozen?,
 :public_methods,
 :singleton_methods,
 :!,
 :!=,
 :__send__,
 :equal?,
 :instance_eval,
 :instance_exec,
 :__id__]

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/1106

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-07

Discussion