Thursday, March 19, 2020

How to Create and Use Hashes in Ruby

How to Create and Use Hashes in Ruby Arrays are not the only way to manage collections of variables in Ruby. Another type of collection of variables is the hash, also called an associative array. A hash is like an array in that its a variable that stores other variables. However, a hash is unlike an array in that the stored variables are not stored in any particular order, and they are retrieved with a key instead of by their position in the collection. Create a Hash With Key/Value Pairs A hash is useful to store what are called key/value pairs. A key/value pair has an identifier to signify which variable of the hash you want to access and a variable to store in that position in the hash. For example, a teacher might store a students grades in a hash. Bobs grade would be accessed in a hash by the key Bob and the variable stored at that location would be Bobs grade. A hash variable can be created the same way as an array variable. The simplest method is to create an empty hash object and fill it with key/value pairs. Note that the index operator is used, but the students name is used instead of a number.​​ Remember that hashes are unordered, meaning there is no defined beginning or end as there is in an array. So, you cannot append to a hash. Values are simply inserted into the hash using the index operator. #!/usr/bin/env rubygrades Hash.newgrades[Bob] 82grades[Jim] 94grades[Billy] 58puts grades[Jim] Hash Literals Just like arrays, hashes can be created with hash literals. Hash literals use the curly braces instead of square brackets and the key value pairs are joined by . For example, a hash with a single key/value pair of Bob/84 would look like this: { Bob 84 }. Additional key/value pairs can be added to the hash literal by separating them with commas. In the following example, a hash is created with the grades for a number of students. #!/usr/bin/env rubygrades { Bob 82,Jim 94,Billy 58}puts grades[Jim] Accessing Variables in the Hash There may be times when you must access each variable in the hash. You can still loop over the variables in the hash using the each loop, though it wont work the same way as using the each loop with array variables. Because a hash is unordered, the order in which each will loop over the key/value pairs may not be the same as the order in which you inserted them. In this example, a hash of grades will be looped over and printed. #!/usr/bin/env rubygrades { Bob 82,Jim 94,Billy 58}grades.each do|name,grade|puts #{name}: #{grade}end

Tuesday, March 3, 2020

A Beginners Guide to the Renaissance

A Beginners Guide to the Renaissance The Renaissance was a cultural and scholarly movement which stressed the rediscovery and application of texts and thought from classical antiquity, occurring in Europe c. 1400 – c. 1600. The Renaissance can also refer to the period of European history spanning roughly the same dates. Its increasingly important to stress that the Renaissance had a long history of developments that included the twelfth-century renaissance and more. What Was the Renaissance? There remains debate about what exactly constituted the Renaissance. Essentially, it was a cultural and intellectual movement, intimately tied to society and politics, of the late 14th to early 17th centuries, although it is commonly restricted to just the 15th and 16th centuries. It is considered to have originated in Italy. Traditionally people have claimed it was stimulated, in part, by Petrarch, who had a passion for rediscovering lost manuscripts and a fierce belief in the civilizing power of ancient thought and in part by conditions in Florence. At its core, the Renaissance was a movement dedicated to the rediscovery and use of classical learning, that is to say, knowledge and attitudes from the Ancient Greek and Roman eras. Renaissance literally means ‘rebirth’, and Renaissance thinkers believed the period between themselves and the fall of Rome, which they labeled the Middle Ages, had seen a decline in cultural achievement compared with the earlier eras. Participants intended, through the study of classical texts, textual criticism, and classical techniques, to both reintroduce the heights of those ancient days and improve the situation of their contemporaries. Some of these classical texts survived only amongst Islamic scholars and were brought back to Europe at this time. The Renaissance Period â€Å"Renaissance† can also refer to the period, c. 1400 – c. 1600. â€Å"High Renaissance† generally refers to c. 1480 – c. 1520. The era was dynamic, with European explorers â€Å"finding† new continents, the transformation of trading methods and patterns, the decline of feudalism (in so far as it ever existed), scientific developments such as the Copernican system of the cosmos and the rise of gunpowder. Many of these changes were triggered, in part, by the Renaissance, such as classical mathematics stimulating new financial trading mechanisms, or new techniques from the east boosting ocean navigation. The printing press was also developed, allowing Renaissance texts to be disseminated widely (in actual fact this print was an enabling factor rather than a result). Why Was This Renaissance Different? Classical culture had never totally vanished from Europe, and it experienced sporadic rebirths. There was the Carolingian Renaissance in the eighth to ninth centuries and a major one in the â€Å"Twelfth Century Renaissance†, which saw Greek science and philosophy returned to European consciousness and the development of a new way of thinking which mixed science and logic called Scholasticism. What was different in the fifteenth and sixteenth centuries was that this particular rebirth joined together both the elements of scholarly inquiry and cultural endeavor with social and political motivations to create a much broader movement, albeit one with a long history. The Society and Politics Behind the Renaissance Across the fourteenth century, and perhaps before, the old social and political structures of the medieval period broke down, allowing new concepts to rise. A new elite emerged, with new models of thought and ideas to justify themselves; what they found in classical antiquity was something to use both as a prop and a tool for their aggrandizement. Exiting elites matched them to keep pace, as did the Catholic Church. Italy, from which the Renaissance evolved, was a series of city-states, each competing with the others for civic pride, trade, and wealth. They were largely autonomous, with a high proportion of merchants and artisans thanks to the Mediterranean trade routes. At the very top of Italian society, the rulers of the key courts in Italy were all â€Å"new men†, recently confirmed in their positions of power and with newly gained wealth, and they were keen to demonstrate both. There was also wealth and the desire to show it below them. The Black Death had killed millions in Europe and left the survivors with proportionally greater wealth, whether through fewer people inheriting more or simply from the increased wages they could demand. Italian society and the results of the Black Death allowed for much greater social mobility, a constant flow of people keen to demonstrate their wealth. Displaying wealth and using culture to reinforce your social and political was an important aspect of life in that period, and when artistic and scholarly movements turned back to the classical world at the start of the fifteenth century there were plenty of patrons ready to support them in these endeavors to make political points. The importance of piety, as demonstrated through commissioning works of tribute, was also strong, and Christianity proved a heavy influence for thinkers trying to square Christian thought with that of â€Å"pagan† classical writers. The Spread of the Renaissance From its origins in Italy, the Renaissance spread across Europe, the ideas changing and evolving to match local conditions, sometimes linking into existing cultural booms, although still keeping the same core. Trade, marriage, diplomats, scholars, the use of giving artists to forge links, even military invasions, all aided the circulation. Historians now tend to break the Renaissance down into smaller, geographic, groups such as the Italian Renaissance, The English Renaissance, the Northern Renaissance (a composite of several countries) etc. There are also works which talk about the Renaissance as a phenomenon with global reach, influencing – and being influenced by – the east, Americas, and Africa. The End of the Renaissance Some historians argue that the Renaissance ended in the 1520s, some the 1620s. The Renaissance didn’t just stop, but its core ideas gradually converted into other forms, and new paradigms arose, particularly during the scientific revolution of the seventeenth century. It would be hard to argue we are still in the Renaissance (as you can do with the Enlightenment), as culture and learning move in a different direction, but you have to draw the lines from here back to then (and, of course, back to before then). You could argue that new and different types of Renaissance followed (should you want to write an essay). The Interpretation of the Renaissance The term ‘renaissance’ actually dates from the nineteenth century and has been heavily debated ever since, with some historians questioning whether it’s even a useful word anymore. Early historians described a clear intellectual break with the medieval era, but in recent decades scholarship has turned to recognize growing continuity from the centuries before, suggesting that the changes Europe experienced were more an evolution than a revolution. The era was also far from a golden age for everyone; at the start, it was very much a minority movement of humanists, elites, and artists, although it disseminated wider with printing. Women, in particular, saw a marked reduction in their educational opportunities during the Renaissance. Its no longer possible to talk of a sudden, all changing golden age (or no longer possible and be considered accurate), but rather a phase that wasnt entirely a move forward, or that dangerous historical problem, progress. Renaissance Art There were Renaissance movements in architecture, literature, poetry, drama, music, metals, textiles and furniture, but the Renaissance is perhaps best known for its art. Creative endeavor became viewed as a form of knowledge and achievement, not simply a way of decoration. Art was now to be based on observation of the real world, applying mathematics and optics to achieve more advanced effects like perspective. Paintings, sculpture and other art forms flourished as new talents took up the creation of masterpieces, and enjoying art became seen as the mark of a cultured individual. Renaissance Humanism Perhaps the earliest expression of the Renaissance was in humanism, an intellectual approach which developed among those being taught a new form of curriculum: the studia humanitatis, which challenged the previously dominant Scholastic thinking. Humanists were concerned with the features of human nature and attempts by man to master nature rather than develop religious piety. Humanist thinkers implicitly and explicitly challenged the old Christian mindset, allowing and advancing the new intellectual model behind the Renaissance. However, tensions between humanism and the Catholic Church developed over the period, and humanist learning partly caused the Reformation. Humanism was also deeply pragmatic, giving those involved the educational basis for work in the burgeoning European bureaucracies. It is important to note that the term ‘humanist’ was a later label, just like â€Å"renaissance†. Politics and Liberty The Renaissance used to be regarded as pushing forward a new desire for liberty and republicanism - rediscovered in works about the Roman Republic- even though many of the Italian city-states were taken over by individual rulers. This view has come under close scrutiny by historians and partly rejected, but it did cause some Renaissance thinkers to agitate for greater religious and political freedoms over later years. More widely accepted is the return to thinking about the state as a body with needs and requirements, taking politics away from the application of Christian morals and into a more pragmatic, some might say devious, world, as typified by the work of Machiavelli. There was no marvelous purity in Renaissance politics, just the same twisting about as ever. Books and Learning Part of the changes brought by the Renaissance, or perhaps one of the causes, was the change in attitude to pre-Christian books. Petrarch, who had a self-proclaimed â€Å"lust† to seek out forgotten books among the monasteries and libraries of Europe, contributed to a new outlook: one of (secular) passion and hunger for the knowledge. This attitude spread, increasing the search for lost works and increasing the number of volumes in circulation, in turn influencing more people with classical ideas. One other major result was a renewed trade in manuscripts and the foundation of public libraries to better enable widespread study. Print then enabled an explosion in the reading and spread of texts, by producing them faster and more accurately, and led to the literate populations who formed the basis of the modern world.