Bits

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Mid – 1 Bits

Multiple choice questions.


1. What is a common way to group related code in Ruby?
a) Using complex macros and preprocessor directives.
b) By defining classes that encapsulate data and functionality.
c) Relying heavily on global variables for data sharing.
d) Separating code into multiple scripts without a clear structure.
2. What is a common data structure used in Ruby to store collections of items?
a) Hashes (key-value pairs) offer flexibility for storing different data types.
b) Multidimensional arrays are the primary choice.
c) Stacks and queues are the most commonly used data structures.
d) Complex custom data structures are typically necessary for most projects.
3. What is the Model-View-Controller (MVC) architecture pattern utilized by
Rails?
a) It primarily deals with user interface design and styling.
b) It requires writing all code within a single large script.
c) It emphasizes complex object-oriented design patterns.
d) It focuses on separation of concerns for different application layers.
4. What is an example of a component managed by Rails for building web
applications?
a) Low-level network communication protocols.
b) Database connections and data access through models.
c) Web server configuration and deployment details.
d) User interface elements like buttons and forms without any logic.
5. Ruby is:
a) A compiled language like C++.
b) A statically typed language with strict variable declarations.
c) A scripting language primarily used for web development.
d) An interpreted language, meaning code is executed line by line.
6. What is a characteristic of widgets in Tk?
a) They are complex graphical objects requiring extensive coding for customization.
b) They represent low-level drawing primitives like lines and shapes.
c) They are pre-built UI elements like buttons, labels, and text boxes.
d) Developers need to create custom widgets from scratch for most functionalities.
7. What is an example of a Tk widget used for displaying text?
a) The Label widget is specifically designed to display text.
b) The Button widget is suitable for displaying text.
c) The Entry widget can only display a single line of text for user input.
d) Tk doesn't provide any dedicated widget for displaying text, requiring custom
solutions.
8. How can you define an action to be triggered when a button is clicked in a Tk
application?
a) By manually checking the button's state within the main application loop.
b) Using the bind method to associate a function with the button's click event.
c) Relying on external libraries for event handling capabilities.
d) Directly modifying the button's internal code to define its behavior.
9. How are Ruby objects represented in C code for interacting with the Ruby
interpreter?
a) As custom data structures defined specifically for each object type.
b) By directly manipulating Ruby’s internal memory layout, which is not
recommended.
c) As pointers to a structure that holds information about the object's type and data.
d) none

10. What is the VALUE type in C extensions for Ruby?


a) It is a generic type that can hold a pointer to any Ruby object or an immediate
value.
b) It represents a specific data type like integer or string.
c) It defines a function for accessing and manipulating Ruby objects from C code.
d) All of the above
11. What are immediate values in Ruby, represented differently from pointers in C
extensions?
a) They are complex objects requiring special memory allocation routines.
b) They are simple data types like integers, symbols, or true/false values stored
directly.
c) They are custom data structures defined by the programmer in C extensions.
d) none
12. How might the Jukebox extension access functionalities of the Ruby language
from C?
a) It cannot directly interact with Ruby code elements from C.
b) It can call Ruby functions or methods provided by the Ruby interpreter's C API.
c) It needs to be entirely rewritten in Ruby to interact with other Ruby code.
13. How does Ruby handle type mismatches during operations?
a) Type checks are performed at runtime, potentially raising exceptions for
incompatible operations.
b) The program will always compile with type errors, preventing execution.
c) The Ruby interpreter silently converts types as needed, potentially leading to
unexpected behavior.
14. What is a benefit of embedding a Ruby interpreter within another programming
language?
a) It replaces the need to learn and use Ruby as a separate language.
b) It allows leveraging Ruby's scripting capabilities and libraries within a different
language's environment.
c) It significantly increases the complexity of the overall program's development and
maintenance.
15. What happens to memory allocated for Ruby objects in C extensions when they
are no longer referenced in Ruby code?
a) The memory is never released and can lead to memory leaks.
b) The C extension developer is responsible for manually freeing the allocated
memory.
c) Ruby's garbage collector automatically reclaims the memory when it's no longer
needed.
16. What is the key difference between a script and a program?
a) Scripts are always interpreted, while programs are compiled.
b) Scripts are simpler and shorter, while programs are complex and lengthy.
c) Scripts can't access system resources, while programs can.
d) There's no significant difference; they are interchangeable terms.
17. What is the primary role of a script?
a) To create a user interface for a graphical application.
b) To automate repetitive tasks or perform specific functionalities within a system.
c) To define the overall structure and logic of a large software program.
d) To directly interact with hardware components of a computer.
18. How has the use of scripting languages evolved in recent years?
a) Scripting languages are being replaced by compiled languages for all development
tasks.
b) Scripting languages are primarily used for legacy systems and are not widely
adopted in modern development.
c) Scripting languages are increasingly used for web development, automation, and
scripting applications within larger software projects.
19. What is a common characteristic of scripting languages compared to compiled
languages?
a) Scripting languages require extensive memory management by the developer.
b) Scripting languages are always slower in execution compared to compiled
languages.
c) Scripting languages offer more powerful features and control flow structures.
d) Scripting languages are typically interpreted line by line, while compiled languages
are translated into machine code before execution.
20. What is an advantage of using scripting languages for automation tasks?
a) Scripting languages require extensive coding experience to use effectively.
b) They are often easier to learn and write compared to compiled languages, making
them suitable for quick automation solutions.
c) Debugging scripts can be more complex due to the lack of static type checking.
d) Scripting languages are less portable and may not run on different operating
systems.
Answers
1. B
2. A
3. D
4. B
5. D
6. C
7. A
8. B
9. C
10. A
11. B
12. B
13. A
14. B
15. C
16. A
17. B
18. C
19. D
20. B
Fill in the blanks
1. Ruby programs typically start with a _______ (shebang) line specifying
the Ruby interpreter.
2. Code is usually organized into _______ (methods) that perform specific
tasks.
3. The _______ (return) statement is used to exit a method and optionally
return a value.
4. The _______ (gem) command is used to install and manage Ruby
libraries.
5. Gems are downloaded and installed from the _______ (RubyGems)
repository.
6. _______ (require) statements in your Ruby code load the functionalities
of installed gems.
7. You can specify specific gem versions during installation using the
_______ (version) option.
8. The _______ (bundle) command is used to manage gems within a Rails
project.
9. The _______ (Canvas) widget allows you to draw complex shapes, images, and
text on a dedicated area within your application's window.
10. The mainloop() function in a Tk application is used to _______ (start the event
loop) and wait for user interaction on the graphical user interface.
11. The _______ (VALUE) type in C extensions acts as a generic representation
for Ruby objects.
12. A Jukebox extension written in C can utilize Ruby's C API to call _______
(Ruby functions) or methods provided by the Ruby interpreter.
13. Embedding a Ruby interpreter allows for _______ (scripting capabilities) of
Ruby within another language's environment.
14. When allocating memory for Ruby objects in C extensions, it's recommended
to use _______ (functions provided by Ruby) to ensure proper garbage
collection.
15. C extensions for Ruby interact with objects through _______ (pointers) or
immediate values depending on the object type.
16. The use of the term "script" in a computing context originated with the
development of _______ (shell scripts) in early operating systems like Unix.
17. Scripting languages are widely used for _______ (web development) tasks,
including server-side scripting and interacting with web servers.
18. Scripting languages can be used for _______ (data processing) and
manipulation, making them valuable tools for data analysis and transformation
tasks.
19. _______ (JavaScript) is the most popular scripting language for web
development, used to create dynamic and interactive web pages.
20. Scripting languages are also employed for _______ (automation) of various
tasks in different domains.

You might also like