def square(number)
number * number
end
method = method(:square)
block = lambda {|number| number*number}
numbers = [1, 2, 3]
#prepare to get the same answer
p numbers.collect(&method)
#result: [1, 4, 9]
p numbers.collect(&block)
#result: [1, 4, 9]
#This fails
class Symbol
def call(*all)
method(self).call(*all)
end
end
p numbers.collect(&:square)
#result: ERROR!
class Symbol
def to_proc
method(self).to_proc
end
end
p numbers.collect(&:square)
#result: [1, 4, 9]
class MyComplicatedCalculation
#lots of instance variables..too heavy for a mere Proc
def to_proc
#calculations that could end world hunger go here
#For now, simply return a simple answer
lambda { | number | 42 }
end
end
p numbers.collect(&MyComplicatedCalculation.new)
#result: [42, 42, 42]
Robert W. Welkos of the Los Angeles Times is reporting that Joey Fatale, the 4-foot, 4-inch New Yorker who heads the all-dwarf KISS tribute band MINIKISS, is denying published reports that he tried to sneak past security last month at the Hard Rock Hotel and Casino in Las Vegas to confront a rival band leader, 4-foot "Little" Tim Loomis of TINY KISS, for allegedly ripping off his idea for such a group.]]>
Loomis, a former drummer for MINIKISS, was performing with TINY KISS, which includes three little people and a 350-pound woman, on St. Patrick's Day at Beacher's Madhouse, a Las Vegas variety show, when the incident occurred.
Show host Jeff Beacher told The Times on Monday that Fatale "tried to sneak in saying he was TINY KISS" and had to be escorted from the premises. According to the New York Post, Fatale's lawyers sent a legal cease-and-desist letter to the show trying to shut down the act.
Loomis told the Post: "[Fatale] came out here [to Las Vegas] and tried to cause trouble, so I had him 86'd from the Hard Rock. The impression I got was that he was looking for a fight. He'd been threatening me over the phone."
But Fatale disputed the accusation, telling The Times: "This whole thing about me going to the Hard Rock with my gang — that didn't happen. What happened was, I went there because somebody told me [TINY KISS was] doing the show that night…. Nobody escorted me out of there. I went there by myself to approach them as a gentleman."
Fatale says he has "nothing to say" about Loomis, except, "He's a nice guy." And, he added, "This is all a big publicity act for the guy at Beacher's."
elementsIn: anElement do: aOneArgBlock depthFirst: aBoolean
| left children |
left := OrderedCollection with: anElement.
[left isEmpty]
whileFalse:
[| next |
next := aBoolean ifTrue: [left removeLast] ifFalse: [left removeFirst].
(aOneArgBlock value: next) == false
ifFalse: [children := OrderedCollection new.
next elementsDo: [:each | aBoolean ifTrue: [children addFirst: each] ifFalse: [children addLast: each]].
left addAll: children]]
pvtDo: doBlock depthFirst: isDepthFirst
| searchQueue dyadic |
dyadic := self pvtCurryForContinue: doBlock.
searchQueue := OrderedCollection withAll: self pvtChildren.
[searchQueue isEmpty] whileFalse:
[| next continue |
next := self class on: searchQueue removeFirst.
continue := [next addChildrenTo: searchQueue depthFirst: isDepthFirst].
dyadic value: next value: continue]
pvtCurryForContinue: doBlock
^doBlock numArgs == 1
ifTrue:
[[:each :continue |
doBlock value: each.
continue value]]
ifFalse: [doBlock]
When | April 4, 2006, 7pm-9pm |
Where | Cafe Gelato 156th & Dodge 445-4460 |
Many folks haven't figured out that I too am a fan of Ruby.
Does anyone agree that the notion of packages / namespaces should be a part of every modern language?
I also couldn't find the equivalent of instance variables. Wouldn't that make reuse at an enterprise-level somewhat problematic?
Shouldn't the notion of methods being public, private and protected also be a part of every modern language?
Does anyone in the community acknowledge that software vendors and even many large enterprises don't build on top of scripting languages because they don't want their intellectual property so discoverable?
Ruby seems to be missing something that is otherwise fundamental in other languages which is support for Regular Expressions.
Ruby folks as another predictor (different from guarantee) tend to not design (Yes, I know the agile party line here) and are successful in getting applications to work quickly but tend to skip out on long term maintainability. Maybe the best thing that Java folks can do for the Ruby community is to bring more of a software engineering mindset to development.
nextWord
| wordString |
wordStream := String new writeStream.
input do:
[:next |
next isAlphaNumeric
ifTrue: [wordStream nextPut: next]
ifFalse:
[wordString := wordStream contents.
wordString isEmpty ifFalse: [^Word on: wordString]].
wordString := wordStream contents.
^wordString isEmpty
ifTrue: [nil]
ifFalse: [Word on: wordString]
nextWord
| return |
wordStream := String new writeStream.
return := [| wordString |
wordString := wordStream contents.
wordString isEmpty ifFalse: [^Word on: wordString]].
input do:
[:next |
next isAlphaNumeric
ifTrue: [wordStream nextPut: next]
ifFalse: [return value]].
return value.
^nil
Some Smalltalk dialects attempt to solve this problem by using a special naming convention to specify internal methods. In the Squeak dialect, for example, methods whose names begin with pvt are effectively private: the compiler ensures that these messages can be sent only to self. However, this approach not only prevents accesses to such internal methods from outside of their class but also from other objects of the same class. Thus, the pvt convention is a form
of object encapsulation: in practice it is often too strict, because it prevents many commonly used data structures and patterns from being implemented. As with Python’s double underscore, this approach is clumsy because changing the access attributes of a method requires renaming it.
The utility of the pvt feature is reflected in the Squeak image: although this feature has been available for years, only 9 out of about 40,000 methods in the latest Squeak image use it.
| result |
result := OrderedCollection new.
RTCriteria new
methodsWhere:
[:each |
each beginsWith: 'pvt'];
methodsDo:
[:eachClass :eachMethod |
result add: (eachClass -> eachMethod)].
result
When | March 7, 2006, 7pm-9pm |
Where | Cafe Gelato 156th & Dodge 445-4460 |
class Album {
String title;
String artist;
//Assume the usual getters/setters and general behavior
public static Album[] byArtist(String anArtistName) {
...
}
}
class Album {
String title;
Artist artist;
}
class Artist {
String name;
Album[] albums;
}