background preloader

Ruby

Ruby

Model–view–controller Model–view–controller (MVC) is a software pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.[1][2] The central component, the model, consists of application data, business rules, logic and functions. A view can be any output representation of information, such as a chart or a diagram. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants. The third part, the controller, accepts input and converts it to commands for the model or view.[3] Component interactions[edit] A typical collaboration of the MVC components In addition to dividing the application into three kinds of components, the Model–view–controller (MVC) design defines the interactions between them.[4] Use in web applications[edit] History[edit] See also[edit]

A Quick (and Hopefully Painless) Ride Through Ruby (with Cartoon Foxes) :: Why's (Poignant) Guide to Ruby Yeah, these are the two. My asthma’s kickin’ in so I’ve got to go take a puff of medicated air just now. Be with you in a moment. I’m told that this chapter is best accompanied by a rag. Indeed, we’ll be racing through the whole language. 1. My conscience won’t let me call Ruby a computer language. But what do you call the language when your brain begins to think in that language? We can no longer truthfully call it a computer language. Read the following aloud to yourself. 5.times { print "Odelay!" In English sentences, punctuation (such as periods, exclamations, parentheses) are silent. Which is exactly what this small Ruby program does. exit unless "restaurant".include? Here we’re doing a basic reality check. Ever seen a programming language use question marks so effectively? ['toast', 'cheese', 'wine'].each { |food| print food.capitalize } While this bit of code is less readable and sentence-like than the previous examples, I’d still encourage you to read it aloud. 2. Variables Numbers

codecademy Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is: High-level, meaning reading and writing Ruby is really easy—it looks a lot like regular English!Interpreted, meaning you don't need a compiler to write and run Ruby. You can write it here at Codecademy or even on your own computer (many are shipped with the Ruby interpreter built in—we'll get to the interpreter later in this lesson).Object-oriented, meaning it allows users to manipulate data structures called objects in order to build and execute programs. This course assumes no previous knowledge of Ruby in particular or programming/computer science in general. Don't repeat yourself Applying DRY[edit] DRY vs WET solutions[edit] Violations of DRY are typically referred to as WET solutions, which is commonly taken to stand for either "write everything twice" or "we enjoy typing".[2][3] See also[edit] References[edit] External links[edit]

Getting a Git Repository You can get a Git project using two main approaches. The first takes an existing project or directory and imports it into Git. The second clones an existing Git repository from another server. Initializing a Repository in an Existing Directory If you’re starting to track an existing project in Git, you need to go to the project’s directory and type $ git init This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton. If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. $ git add *.c $ git add README $ git commit -m 'initial project version' We’ll go over what these commands do in just a minute. Cloning an Existing Repository If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone. You clone a repository with git clone [url].

Ruby en vingt minutes Introduction Ce court tutoriel ne devrait pas prendre plus de vingt minutes de votre temps. Il part du principe que vous avez déjà installé Ruby ; si ce n’est pas le cas, il vous est chaleureusement conseillé de le faire avant de poursuivre votre lecture. Note: le traducteur a ici considéré qu’il était plus pertinent de conserver l’entièreté du code en anglais, plutôt que de présenter un mélange en « franglais » de mot-clés anglais et noms de variables français. L’usage d’un langage de programmation, quel qu’il soit, nécessite hélas (?) Interactive Ruby Une première approche de Ruby, la plus simple, consiste à utiliser IRB (Interactive Ruby) dans un terminal : si vous utilisez macOS, ouvrez un Terminal et tapez irb, puis appuyez sur [Entrée] ; si vous êtes sous Linux, ouvrez une console et tapez irb, puis appuyez sur [Entrée] ; si enfin, vous utilisez Windows, lancez Interactive Ruby qui se trouve dans la section Ruby du menu Démarrer > Applications. irb(main):001:0> Voilà, IRB est lancé.

Convention over configuration Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility. The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called “sales” by default. It is only if one deviates from this convention, such as calling the table “sale”, that one needs to write code regarding these names. When the convention implemented by the tool matches the desired behavior, it behaves as expected without having to write configuration files. Motivation[edit] Some frameworks need multiple configuration files, each with many settings. Usage[edit] The Maven software tool auto-generated this directory structure for a Java project. Many modern frameworks use a convention over configuration approach.

Home Active record pattern This pattern is commonly used by object persistence tools, and in object-relational mapping (ORM). Typically, foreign key relationships will be exposed as an object instance of the appropriate type via a property. Implementations[edit] Implementations of the concept can be found in various frameworks for many programming environments. part = new Part() part.name = "Sample part" part.price = 123.45 part.save() will create a new row in the parts table with the given values, and is roughly equivalent to the SQL command INSERT INTO parts (name, price) VALUES ('Sample part', 123.45); Conversely, the class can be used to query the database: b = Part.find_first("name", "gearbox") This will find a new Part object based on the first matching row from the parts table whose name column has the value "gearbox". SELECT * FROM parts WHERE name = 'gearbox' LIMIT 1; -- MySQL or PostgreSQL ColdFusion[edit] ColdFusion has an open source implementation of the Active Record pattern. PHP[edit] Ruby[edit] Java[edit]

Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns

Related: