Last Updated: February 25, 2016
·
488
· gregorym

List Cocoa methods

I am learning Macruby so I am building a dummy application to learn it. I wanted to have a button and when it is clicked, it opens a menu. So I looked at the documentation and found the method setMenuBarVisible for the NSMenu class but when I ran my code I had this error:

undefined method `setMenuBarVisible' for #<NSMenu:0x400326960> (NoMethodError)

So I fired up macirb to see if that method actually exists.

$ macruby
> framework 'Cocoa'
> menu = NSMenu.new
> menu.methods.sort
=> [:!, :!=, :!~, :<=>, :==, :===, :=~, :Complex, :Rational, :__callee__, :__id__, :__method__, :__send__, :__type__, :clear_history!, :clone, :define_singleton_method, :dup, :enum_for, :eql?, :equal?, :extend, :freeze, :frozen?, :gem, :h, :h!, :hash, :history, :history!, :initialize_clone, :initialize_dup, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_variable_defined?, :instance_variable_get, :instance_variable_set, :instance_variables, :irb, :is_a?, :kind_of?, :method, :methods, :nil?, :object_id, :private_methods, :protected_methods, :public_method, :public_methods, :public_send, :require, :respond_to?, :respond_to_missing?, :send, :singleton_methods, :taint, :tainted?, :tap, :to_enum, :to_plist, :to_s, :to_yaml, :to_yaml_properties, :to_yaml_style, :trust, :untaint, :untrust, :untrusted?, :y, :yaml_as]

Surprisingly it returns only the Ruby methods and not the Objectice-C methods. I searched online and found the proper way to see all the methods.

> menu.methods(true, true).sort
> # I am not copying/pasting the result because it is really long :)