`ls` to inspect object

Today I learned we can use ls to…

Show methods, constants, and variables. -g [query] or -G [query] allows you to filter out the output. Ruby 3.2 Official Documentation

Examples

Looking at a class Greeting I created:

?> class Gree…


This content originally appeared on DEV Community and was authored by Kelly Popko

Today I learned we can use ls to...

Show methods, constants, and variables. -g [query] or -G [query] allows you to filter out the output. Ruby 3.2 Official Documentation

Examples

Looking at a class Greeting I created:

?> class Greeting
?>   attr_accessor :name
?>
?>   def initialize(name)
?>     self.name = name
?>   end
?>
?>   def to_s
?>     'Hello, %s' % name
?>   end
>> end
=> :to_sG
>> ls Greeting
Greeting#methods: name  name=  speak  to_s
>> ls Greeting.new('foo')
Greeting#methods: name  name=  speak  to_s
instance variables: @name

Looking at a built-in Ruby class, Struct

>> ls Struct
Struct.methods: new
Struct#methods:
  ==    []    []=     deconstruct  deconstruct_keys  dig  each  each_pair  eql?  filter  hash  inspect  length  members  pretty_print  pretty_print_cycle  select  size  to_a
  to_h  to_s  values  values_at
Enumerable#methods:
  all?        any?        chain            chunk             chunk_while   collect     collect_concat  compact   count       cycle   detect      drop   drop_while  each_cons
  each_entry  each_slice  each_with_index  each_with_object  entries       filter_map  find            find_all  find_index  first   flat_map    grep   grep_v      group_by
  include?    inject      lazy             map               max           max_by      member?         min       min_by      minmax  minmax_by   none?  one?        partition
  reduce      reject      reverse_each     slice_after       slice_before  slice_when  sort            sort_by   sum         take    take_while  tally  to_set      uniq
  zip

Sources


This content originally appeared on DEV Community and was authored by Kelly Popko


Print Share Comment Cite Upload Translate Updates
APA

Kelly Popko | Sciencx (2025-07-09T00:04:35+00:00) `ls` to inspect object. Retrieved from https://www.scien.cx/2025/07/09/ls-to-inspect-object/

MLA
" » `ls` to inspect object." Kelly Popko | Sciencx - Wednesday July 9, 2025, https://www.scien.cx/2025/07/09/ls-to-inspect-object/
HARVARD
Kelly Popko | Sciencx Wednesday July 9, 2025 » `ls` to inspect object., viewed ,<https://www.scien.cx/2025/07/09/ls-to-inspect-object/>
VANCOUVER
Kelly Popko | Sciencx - » `ls` to inspect object. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/09/ls-to-inspect-object/
CHICAGO
" » `ls` to inspect object." Kelly Popko | Sciencx - Accessed . https://www.scien.cx/2025/07/09/ls-to-inspect-object/
IEEE
" » `ls` to inspect object." Kelly Popko | Sciencx [Online]. Available: https://www.scien.cx/2025/07/09/ls-to-inspect-object/. [Accessed: ]
rf:citation
» `ls` to inspect object | Kelly Popko | Sciencx | https://www.scien.cx/2025/07/09/ls-to-inspect-object/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.