Created
August 24, 2012 11:21
-
-
Save keeperofthenecklace/3449365 to your computer and use it in GitHub Desktop.
IRB - Useful commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ IRB ****Let you into Ruby Interpreter | |
1.9.3-p194 :088 > use TAB key to autocomplete. | |
1.9.3-p194 :089 > help | |
Enter the method name you want to look up. | |
You can use tab to autocomplete. | |
Enter a blank line to exit. | |
>> AbstractController | |
###### | |
loading a file.rb | |
###### | |
1.9.3-p194 :053 > load 'ruby_script.rb' | |
1.9.3-p194 :053 > aSong = Song.new | |
1.9.3-p194 :053 > aSong.methods | |
=> [:name, :name=, :artist, :artist=, :duration, :duration=, :to_s, .... | |
1.9.3-p194 :053 > aSong.instance_variables | |
=> [:@name, :@artist, :@duration, :@plays] | |
1.9.3-p194 :062 > aSong.class | |
=> Song | |
############ | |
Searching a method in your obj, eg aSong | |
############ | |
1.9.3-p194 :053 > aSong.methods.grep(/ar/) | |
=> [:artist, :artist=, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?] | |
############ | |
Searching a all Array, Harshes, String Methods | |
############ | |
1.9.3-p194 :064 > [].methods | |
=> [:inspect, :to_s, :to_a, :to_ary, :frozen?, :==, :eql?, | |
1.9.3-p194 :066 > {}.methods | |
=> [:rehash, :to_hash, :to_a, :inspect, :to_s, :==, :[], | |
1.9.3-p194 :067 > String.methods | |
=> [:try_convert, :allocate, :new, :superclass, :freeze, :===, :==, | |
########### | |
Using grep in your searches | |
########## | |
1.9.3-p194 :069 > [].methods.grep(/^re/) | |
=> [:reverse_each, :reverse, :reverse!, :reject, :reject!, :replace, | |
########### | |
Using helping to lookup method, hashes, string | |
########## | |
1.9.3-p194 :072 > [].methods --help | |
Enter the method name you want to look up. | |
You can use tab to autocomplete. | |
Enter a blank line to exit. | |
>> replace | |
############ | |
Rails Method name Lookup. Starts with a hash tag. eg. #action_method | |
########### | |
1.9.3-p194 :015 > help | |
Enter the method name you want to look up. | |
You can use tab to autocomplete. | |
Enter a blank line to exit. | |
>> a #type a to displays all record eg. beginning with a | |
AbstractController::Base#action_methods | |
AbstractController::Base#available_action? | |
AbstractController::Base::abstract | |
AbstractController::Base::abstract! | |
AbstractController::Base::abstract?.... | |
>> AbstractController::Base #type to displays all class methods and instance Methods | |
AbstractController::Base < Object | |
------------------------------------------------------------------------------ | |
Includes: | |
ActiveSupport::Configurable (from gem actionpack-3.2.8) | |
(from gem actionpack-3.2.8) | |
------------------------------------------------------------------------------ | |
AbstractController::Base is a low-level API. Nobody should be using it | |
directly, and subclasses (like ActionController::Base) are expected to provide | |
their own render method, since rendering means different things | |
depending on the context. | |
------------------------------------------------------------------------------ | |
Class methods: | |
abstract | |
abstract! | |
abstract? | |
action_methods | |
clear_action_methods! | |
controller_path | |
hidden_actions | |
internal_methods | |
method_added | |
Instance methods: | |
action_methods | |
available_action? | |
controller_path | |
process | |
Attributes: | |
attr_reader abstract | |
attr_reader abstract? | |
>>Object, Array, Class, Hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment