object-oriented, general- purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. Bemedianced
= javax.swing.JFrame.new("Window") # Creating a Java JFrame label = javax.swing.JLabel.new("Hello") # We can transparently call Java methods on Java objects, # just as if they were defined in Ruby. frame.add(label) # Invoking the Java method 'add'. frame.setDefaultCloseOperation(javax.swing.JFrame!::EXIT_ON_CLOSE) frame.pack frame.setVisible(true)
is a string' irb(main):0> "and so is this" !=> "and so is this" irb(main):0> a_var = 'interpolated' irb(main):0> "this string can be !#{a_var}" !=> "this string can be interpolated" irb(main):0> "a word".upcase !=> "A WORD" irb(main):0> "two" !<< " strings" # this is different !=> "two strings" irb(main):0> "two" + " strings" # from this !=> "two strings" DATA TYPES Bemedianced
stay the same' !=> "this should stay the same" irb(main):0> A_CONSTANT !<< " but it doesn't!" !=> "this should stay the same but it doesn't!" irb(main):0> A_CONSTANT !=> "this should stay the same but it doesn't!" STRING
stay the same'.freeze !=> "this should stay the same" irb(main):0> TRY_AGAIN !<< " but it doesn't!".freeze RuntimeError: can't modify frozen String from (irb):84 irb(main):0> TRY_AGAIN !=> "this should stay the same" STRING
initialize(species) @species = species end end a_doggo = Animal.new("doggo") a_doggo.species NoMethodError: undefined method `species' for #<Animal:0x007fc9580117f0 @species="doggo">
Singleton attr_accessor :config def initialize @config = YAML.load("initial_config.yml").deep_symbolize_keys end class !<< self def get(key) instance.config[key] end def set(key, value) instance.config[key] = value end end end Configurator.get(:port) !=> 8000
:token_authenticatable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :confirmable, :omniauthable include AccountValidation include HasProfiles include HasAvatar include EmailsRecipient include HasDevices include HasServers include HasPlaylists include HasEntitlements include HasFeatures include HasRoles !!...
receives_newsletter? created_at > DateTime.new(2010) end end class Billing!::User < DelegateClass(Core!::User) def restore_purchase PayPal.restore(id) end end user = Core!::User.where(username: "tommywiseau") billing_user = Billing!::User.new(user) billing_user.restore_purchase
HTTParty.get(meetup_api)["results"].each do |result| define_method(result["member"]["name"].snakecase) do "!#{result["member"]["name"]} is here!" end end end RubyMeetup.new.andrea_rossi !=> "Andrea Rossi is here!"