background preloader

Ruby

Ruby
Related:  Ruby

What is the difference between require_relative and require in Ruby? Ruby Un article de Wikipédia, l'encyclopédie libre. Historique[modifier | modifier le code] Yukihiro « Matz » Matsumoto est le créateur de Ruby. Des changements de version majeurs ont eu lieu[5] : le 25 décembre 1998 pour la version 1.2.0 ;le 13 août 1999 pour la version 1.4.0 ;le 19 septembre 2000 pour la version 1.6.0 ;le 4 août 2003 pour la version 1.8.0 ;le 30 janvier 2009 pour la version 1.9.1 (première version stable de la branche 1.9)[6] ;le 30 octobre 2011 pour la version 1.9.3[7] ;le 24 février 2013 pour la version 2.0.0[8]le 25 décembre 2013 pour la version 2.1.0[9].le 19 août 2015 pour la version 2.2.3.le 24 décembre 2015 pour la version 2.3.0.le 25 décembre 2016 pour la version 2.4.0.le 25 décembre 2017 pour la version 2.5.0.le 25 décembre 2018 pour la version 2.6.0 Depuis l'arrivée d'une documentation anglophone, et du framework web Ruby on Rails en 2004, Ruby a connu un certain engouement qui n'a cessé de croître jusqu'en 2007 dans le monde de la programmation[10]. JRuby[19] XRuby

John Ewart In Ruby, interfaces are not really a part of the programming paradigm. By its very nature, Ruby is designed to be flexible and loosely-typed, and that provides developers with a lot of power. Over the years I’ve seen a number of projects that are written in Ruby become internally inconsistent. What I mean by this is that developers decide that their abstractions or structure isn’t working and instead of working from the bottom up, just start writing modifications to make things work. Take, for example, Fog.io, which I mentioned in a previous post. Just because Ruby does not formally support interfaces in the same way Java or C# do, doesn’t mean that it is impossible to maintain a set of interfaces in your code and ensure that developers are adhering to those interfaces. Take for example, some code in Ruby that looks like this: An example interface in Ruby class FunctionalInterface def do_thing raise "This is not implemented!"

Learn to Code by Doing Test drive the platform 70% of the Fortune 500 rely on to build technology skills at scale Benchmark skills across your organization with skill assessmentsSee if you have the right people on the projects with Role IQUpskill your teams in critical areas like DevOps, machine learning, cloud, security, infrastructure and more Fill out the form, and we’ll be in touch to set up your team pilot.

Ruby Exceptions Raising An Exception An exception is a special kind of object, an instance of the class Exception or a descendant of that class that represents some kind of exceptional condition; it indicates that something has gone wrong. When this occurs, an exception is raised (or thrown). By default, Ruby programs terminate when an exception occurs. But it is possible to declare exception handlers. An exception handler is a block of code that is executed if an exception occurs during the execution of some other block of code. Ruby has some predefined classes - Exception and its children - that help you to handle errors that can occur in your program. Reference: The above figure is from the Programming Ruby book. The chart above shows that most of the subclasses extend a class known as StandardError. The following method raises an exception whenever it's called. def raise_exception puts 'I am before the raise.' The output is: The raise method is from the Kernel module. Handling an Exception

Lancez-vous dans la programmation avec Ruby Ce cours est destiné à tous les curieux qui souhaitent s’initier à la programmation, et aux codeurs qui souhaitent apprendre un nouveau langage. Ici, vous allez découvrir Ruby, un langage de programmation qui a été créé par un informaticien japonais dans les années 1990, avec un objectif en tête : faciliter la vie des développeurs avec une syntaxe et des outils simples et agréables à utiliser. Que vous ayez des connaissances en programmation ou pas, vous pouvez suivre ce cours où vous apprendrez à manipuler les outils de base de Ruby ainsi que ses puissants "objets". Une fois que vous maîtriserez ces notions, vous aurez toutes les cartes en main pour aller plus loin et réaliser vos propres projets, comme par exemple :

DPiR | Companion site to Russ Olsen's book Xavier Nayrac Net::HTTP (Ruby 2.0.0) An HTTP client API for Ruby.¶ ↑ Net::HTTP provides a rich library which can be used to build HTTP user-agents. For more details about HTTP see [RFC2616](www.ietf.org/rfc/rfc2616.txt) Net::HTTP is designed to work closely with URI. URI::HTTP#host, URI::HTTP#port and URI::HTTP#request_uri are designed to work with Net::HTTP. If you are only performing a few GET requests you should try OpenURI. Simple Examples¶ ↑ All examples assume you have loaded Net::HTTP with: require 'net/http' This will also require ‘uri’ so you don’t need to require it separately. The Net::HTTP methods in the following section do not persist connections. Net::HTTP.get('example.com', '/index.html') GET by URI¶ ↑ uri = URI(' GET with Dynamic Parameters¶ ↑ uri = URI(' res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50') puts res.body POST with Multiple Values¶ ↑ How to use Net::HTTP¶ ↑ uri = URI(' Response Data¶ ↑ Proxies¶ ↑ 1xx 2xx 3xx

Ruby and the Sinatra framework Introduction DSL vs GPLGitHub RepositorySinatraHostingExample RequirementsSet-upShotgunLoading pagesLoading templatesStatic resourcesHandling errorsPerformanceHosting our applicationConclusions Introduction In my opinion there's isn't enough good information on the web about how to get started building a Ruby based website (unless you want to use the ever popular Ruby on Rails framework). But even then, it's not as straight forward as you'd think (not for someone new to the language or server-side coding in general). DSL vs GPL Before we go any further, it's worth clarifying the difference between a Domain Specific Language (DSL) and a General Purpose Language (GPL). If we look at a DSL language such as PHP**: it is very easy to build a site using PHP because you can just input some procedural code, upload the file onto a server that supports PHP (and what server doesn't nowadays) and that's all there is to it (! GitHub Repository Sinatra So, let me begin by introducing you to Sinatra. Hosting

String (Ruby 2.2.0) str % arg → new_str click to toggle source Format—Uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. static VALUE rb_str_format_m(VALUE str, VALUE arg) { VALUE tmp = rb_check_array_type(arg); if (! str * integer → new_str click to toggle source Copy — Returns a new String containing integer copies of the receiver. integer must be greater than or equal to 0. "Ho! str + other_str → new_str click to toggle source Concatenation—Returns a new String containing other_str concatenated to str. "Hello from " + self.to_s str << integer → str click to toggle source str << obj → str Append—Concatenates the given object to str. a = "hello "a << "world" a.concat(33) string <=> other_string → -1, 0, +1 or nil click to toggle source nil is returned if the two values are incomparable. <=> is the basis for the methods <, <=, >, >=, and between? tr!

Related: