Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FCC - Technical Documentation Page
<div id="page-wrapper">
<nav id="navbar">
<header></header>
<a href="#Introduction" class="nav-link">Introduction</a>
<a href="#Features_of_Ruby" class="nav-link">Features of Ruby</a>
<a href="#How_to_get_Ruby" class="nav-link">How to get Ruby</a>
<a href="#How_to_compile_and_install_Ruby" class="nav-link">How to compile and install Ruby</a>
<a href="#Seeing_everything_as_an_Object" class="nav-link">Seeing everything as an Object</a>
<a href="#Ruby's_flexibility" class="nav-link">Ruby's flexibility</a>
<a href="#Blocks:_a_Truly_Expressive_Feature" class="nav-link">Blocks: a Truly Expressive Feature</a>
<a href="#Ruby_and_the_Mixin" class="nav-link">Ruby and the Mixin</a>
<a href="#Ruby's_Visual_Appearance" class="nav-link">Ruby's Visual Appearance</a>
</nav>
<main id="main-doc">
<section class="main-section" id="Introduction">
<header>Introduction</header>
<p>Ruby is an interpreted object-oriented programming language often used for web development. It also offers many scripting features to process plain text and serialized files, or manage system tasks. It has an elegant syntax that is natural to read and easy to write. It is simple, straightforward, and extensible.</p>
<p><a href="https://www.ruby-lang.org/">The Ruby language home page</a></p>
</section>
<section class="main-section" id="Features_of_Ruby">
<header>Features of Ruby</header>
<ul>
<li>Simple Syntax</li>
<li>Normal Object-oriented Features (e.g. class, method calls)</li>
<li>Advanced Object-oriented Features (e.g. mix-in, singleton-method)</li>
<li>Operator Overloading</li>
<li><a href="https://docs.ruby-lang.org/en/2.7.0/Exception.html"> Exception</a> Handling</li>
<li>Iterators and Closures</li>
<li>Garbage Collection</li>
<li>Dynamic Loading of Object Files (on some architectures)</li>
<li>Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, Haiku, etc.) cf. <a href="github.com/ruby/ruby/blob/master/doc/contributing.rdoc#platform-maintainers">github.com/ruby/ruby/blob/master/doc/contributing.rdoc#platform-maintainers</a></li>
</ul>
</section>
<section class="main-section" id="How_to_get_Ruby">
<header>How to get Ruby</header>
</section>
<section class="main-section" id="How_to_compile_and_install_Ruby">
<header>How to compile and install Ruby</header>
</section>
<section class="main-section" id="Seeing_everything_as_an_Object">
<header>Seeing Everything as an Object</header>
<p>In Ruby, everything is an object. Every bit of information and code can be given their own properties and actions. Object-oriented programming calls properties by the name instance variables and actions are known as methods. Ruby’s pure object-oriented approach is most commonly demonstrated by a bit of code which applies an action to a number.</p>
<code>5.times { print "We *love* Ruby -- it's outrageous!" }</code>
<p>In many languages, numbers and other primitive types are not objects. Ruby follows the influence of the Smalltalk language by giving methods and instance variables to all of its types. This eases one’s use of Ruby, since rules applying to objects apply to all of Ruby.</p>
</section>
<section class="main-section" id="Ruby's_flexibility">
<header>Ruby's flexibility</header>
<p>Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Essential parts of Ruby can be removed or redefined, at will. Existing parts can be added upon. Ruby tries not to restrict the coder.</p>
<p>For example, addition is performed with the plus (+) operator. But, if you’d rather use the readable word plus, you could add such a method to Ruby’s builtin Numeric class.</p>
<code>
class Numeric
def plus(x)
self.+(x)
end
end
y = 5.plus 6
# y is now equal to 11
</code>
<p>Ruby’s operators are syntactic sugar for methods. You can redefine them as well.</p>
</section>
<section class="main-section" id="Blocks:_a_Truly_Expressive_Feature">
<header>Blocks: a Truly Expressive Feature</header>
<p>Ruby’s block are also seen as a source of great flexibility. A programmer can attach a closure to any method, describing how that method should act. The closure is called a block and has become one of the most popular features for newcomers to Ruby from other imperative languages like PHP or Visual Basic.</p>
<p>Blocks are inspired by functional languages. Matz said, “in Ruby closures, I wanted to respect the Lisp culture3.”</p>
<code>
search_engines =
%w[Google Yahoo MSN].map do |engine|
"http://www." + engine.downcase + ".com"
end
</code>
<p>In the above code, the block is described inside the do ... end construct. The map method applies the block to the provided list of words. Many other methods in Ruby leave a hole open for a coder to write their own block to fill in the details of what that method should do.</p>
</section>
<section class="main-section" id="Ruby_and_the_Mixin">
<header>Ruby and the Mixin</header>
<p>Unlike many object-oriented languages, Ruby features single inheritance only, on purpose. But Ruby knows the concept of modules (called Categories in Objective-C). Modules are collections of methods.</p>
<p>Classes can mixin a module and receive all its methods for free. For example, any class which implements the each method can mixin the Enumerable module, which adds a pile of methods that use each for looping.</p>
<code>
class MyArray
include Enumerable
end
</code>
<p>Generally, Rubyists see this as a much clearer way than multiple inheritance, which is complex and can be too restrictive.</p>
</section>
<section class="main-section" id="Ruby's_Visual_Appearance">
<header>Ruby's Visual Appearance</header>
<p>While Ruby often uses very limited punctuation and usually prefers English keywords, some punctuation is used to decorate Ruby. Ruby needs no variable declarations. It uses simple naming conventions to denote the scope of variables.</p>
<code>
var could be a local variable.
@var is an instance variable.
$var is a global variable.
</code>
<p>These sigils enhance readability by allowing the programmer to easily identify the roles of each variable. It also becomes unnecessary to use a tiresome <code>self</code>. prepended to every instance member.</p>
</section>
</main>
</div>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<!--
Hello Camper!
For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding!
- The freeCodeCamp Team
-->
// coded by @CharlesDeBarros
// eslint-disable-next-line no-unused-vars
const projectName = 'technical-docs-page';
// !! IMPORTANT README:
// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place.
/***********
INSTRUCTIONS:
- Select the project you would
like to complete from the dropdown
menu.
- Click the "RUN TESTS" button to
run the tests against the blank
pen.
- Click the "TESTS" button to see
the individual test cases.
(should all be failing at first)
- Start coding! As you fulfill each
test case, you will see them go
from red to green.
- As you start to build out your
project, when tests are failing,
you should get helpful errors
along the way!
************/
// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!
// Once you have read the above messages, you can delete all comments.
/* Generic Styling */
@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@400;600&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
--black: rgba(0, 0, 0, 1);
--dim-grey: rgba(105, 105, 105, 1);
--faded-white: rgba(255, 255, 255, 1);
--light-grey: rgba(238, 238, 238, 0.8);
--ruby-red: rgba(155, 17, 30, 1);
--white: rgba(255, 255, 255, 1);
}
body {
font-family: 'Roboto Slab', serif;
font-size: 16px;
background-color: var(--light-grey);
}
header {
color: var(--ruby-red);
font-weight: 600;
}
a {
text-decoration: none;
color: var(--ruby-red);
}
ul {
list-style: none;
}
ul li::before {
content: "\2022";
color: var(--ruby-red);
font-weight: bold;
display: inline-block;
width: 1em;
margin-left: -1em;
}
/* Specific Styling */
/* https://www.w3schools.com/howto/howto_css_bullet_color.asp */
/* https://fonts.google.com/specimen/Roboto+Slab?category=Serif&sidebar.open=true&selection.family=Roboto+Slab:wght@400;500 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.